Newbie Question Help with Simple Logic Script… if / else
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Newbie Question Help with Simple Logic Script… if / else
I’m trying to build a simple logic script, attached to a keyboard shortcut, that Toggles between two layouts.
I don’t have any coding background, but I’m familiar with the way excel does a logic statement: =if(logical text, value if true, value if false)
ALWAYS RETURNS 2 PANES NORMAL:
I think the problem I’m having, is that the script doesn’t stop after the first argument is checked, even if it is true:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} loadlayout(2 Panes Normal);}
ALWAYS ALWAYS RETURNS 2 PANES MINIMAL:
I think the problem I’m having here, is the exact opposite, always stops after the first argument is checked:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} else {loadlayout(2 Panes Normal);}
Any help would be greatly appreciated!
I don’t have any coding background, but I’m familiar with the way excel does a logic statement: =if(logical text, value if true, value if false)
ALWAYS RETURNS 2 PANES NORMAL:
I think the problem I’m having, is that the script doesn’t stop after the first argument is checked, even if it is true:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} loadlayout(2 Panes Normal);}
ALWAYS ALWAYS RETURNS 2 PANES MINIMAL:
I think the problem I’m having here, is the exact opposite, always stops after the first argument is checked:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} else {loadlayout(2 Panes Normal);}
Any help would be greatly appreciated!
XYPlorer, Great Form -- Awesome Function
Re: Newbie Question Help with Simple Logic Script… if / else
! is a logical NOT
! is not a valid comparison operator (only as a !=)
Regarding your first example: There is no else?
Should these lines really be scripts or just an example of your (not posted) real scripts?
! is not a valid comparison operator (only as a !=)
Regarding your first example: There is no else?
Should these lines really be scripts or just an example of your (not posted) real scripts?
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Re: Newbie Question Help with Simple Logic Script… if / else
Gotcya; thanks!
Those were my actual scripts (written on one line); when I write them as follows, a popup opens with two scripts that I have to choose from:
if (layout != 2 Panes Minimal) {
loadlayout(2 Panes Minimal);
}
else {
loadlayout(2 Panes Normal);
}
XYPlorer, Great Form -- Awesome Function
Re: Newbie Question Help with Simple Logic Script… if / else
You are comparing strings. Single / double quote them!
Your script isn't properly indenteda popup opens with two scripts that I have to choose from
One of my scripts helped you out? Please donate via Paypal
Re: Newbie Question Help with Simple Logic Script… if / else
Also besides the already mentioned issues, this will never work:
if (layout != 2 Panes Minimal) {
assuming that is meant to be a variable it would need to have a $ prefix, and also assuming what you have shown is your entire script, it would need to have a value assigned to it, which you haven't done.
if (layout != 2 Panes Minimal) {
assuming that is meant to be a variable it would need to have a $ prefix, and also assuming what you have shown is your entire script, it would need to have a value assigned to it, which you haven't done.
Re: Newbie Question Help with Simple Logic Script… if / else
A little more assistance... I think your best bet is to determine what layout feature or possibly a view setting is unique to one of your saved layouts (i.e., a feature that you have in one layout but not the other). SC loadlayout does not provide a return (i.e., text loadlayout () is not going to tell you a layout name that is currently loaded or in use). SC setlayout () will give you the details of the current layout. So for example: one of your saved layouts has a dual pane, the other does not. Then you could test to see if you are currently in a Dual pane. If not, go to layout called "Dual Pane". If you are in a dual pane mode than loadlayout ("Single Pane"). So in this example: Another check might be for a particular view in one layout that's not in the other. (e.g., thumbnail #3 in one layout and the other layout is detail view).
Code: Select all
if(get "#800") {loadlayout ("Single Pane");}
else {loadlayout ("Dual Pane");}
Code: Select all
if(get("View") == '6') {loadlayout ("whatever");}
else {loadlayout ("different whatever");}
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Re: Newbie Question Help with Simple Logic Script… if / else
Cool... thanks; I had basically given up.
Here are teh differences between the layouts:
#663 Show Nav Panels
#671 Breadcrumbs Bar
#670 Status Bar
#681 Address Bar / Toolbar Stacked
I tried this will all four:
if(get "#CMD") {loadlayout ("2 Panes Normal");}
else {loadlayout ("2 Panes Minimal");}
On all 4, they worked on first run; then stopped working.
Regarding Get View... there are no differences in the views; only in the window menu options.
Here are teh differences between the layouts:
#663 Show Nav Panels
#671 Breadcrumbs Bar
#670 Status Bar
#681 Address Bar / Toolbar Stacked
I tried this will all four:
if(get "#CMD") {loadlayout ("2 Panes Normal");}
else {loadlayout ("2 Panes Minimal");}
On all 4, they worked on first run; then stopped working.
Regarding Get View... there are no differences in the views; only in the window menu options.
XYPlorer, Great Form -- Awesome Function
Re: Newbie Question Help with Simple Logic Script… if / else
Something like this should work:
Code: Select all
if (setlayout( , <crlf>) == gettoken(readfile("<xydata>\Layouts\2 Panes Normal.txt"), 2, <crlf>, , 2)) {
loadlayout("2 Panes Minimal"); }
else { loadlayout("2 Panes Normal"); }
Re: Newbie Question Help with Simple Logic Script… if / else
Sorry Lusayalumino I messed up the syntax. It should have beenI forgot a second set of parenthesis around the #CID. Jupe has a very nice solution though. I'd use that.
Code: Select all
if(get("#663")) {loadlayout("2 Panes Minimal");}
else {loadlayout("2 Panes Normal");}
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Re: Newbie Question Help with Simple Logic Script… if / else
That works... THANK YOU KlownBoy!klownboy wrote: ↑06 Oct 2019 13:09 Sorry Lusayalumino I messed up the syntax. It should have beenI forgot a second set of parenthesis around the #CID. Jupe has a very nice solution though. I'd use that.Code: Select all
if(get("#663")) {loadlayout("2 Panes Minimal");} else {loadlayout("2 Panes Normal");}
XYPlorer, Great Form -- Awesome Function
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Re: Newbie Question Help with Simple Logic Script… if / else
This also works perfectly... thanks Jupe!jupe wrote: ↑06 Oct 2019 07:51 Something like this should work:
Code: Select all
if (setlayout( , <crlf>) == gettoken(readfile("<xydata>\Layouts\2 Panes Normal.txt"), 2, <crlf>, , 2)) { loadlayout("2 Panes Minimal"); } else { loadlayout("2 Panes Normal"); }
XYPlorer, Great Form -- Awesome Function
Re: Newbie Question Help with Simple Logic Script… if / else
I mentioned using jupe's version earlier. The reason for that is when you are basing the if/else condition on one attribute, like CID#663, though it's very quick, if you were to use some additional layouts or configurations other than the 2 layouts being cycled, it's possible the layout change could possibly run afoul (though maybe not). Whereas jupe's is essentially checking every attribute of the existing layout, but the disadvantage of that is the reading of the layout file then checking it against all the attributes of the existing layout which equates to some extra milliseconds that you probably wouldn't even notice anyway.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
-
- Posts: 90
- Joined: 13 Aug 2018 07:16
- Location: USA
Re: Newbie Question Help with Simple Logic Script… if / else
Very helpful, thorough, and precise. Almost as though I was being helped by a nuclear engineer
XYPlorer, Great Form -- Awesome Function