Problems with complex IF

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
bernie
Junior Coder
Posts: 47
Joined: Sun Sep 22, 2002 4:16 pm
Location: Virginia

Problems with complex IF

Post by bernie » Tue Jan 11, 2005 12:30 pm

I love the new expression machinery, but I'm having a problem with it.

First, I couldn't remember how to test if a command-line argument to a macro call was present or not. So I had code like:

Let>Default={"This is the default value"}

If>{%commandarg% ""}
Let>commandarg={%Default%}
EndIf>

[I did it this way so the 'default value' is right at the top, instead of hidden amist the code].

Anyhow, I realize [having reread the docs] that that isn't the right test [since apparently a vbl that isn't defined doesn't return "nothing" but rather just returns its own name. So I think I need that to actually be:
If>{%commandarg% = "%commandarg%"}
but I can't get that far: I get a *syntax*error* on that line, and I can't figure out why -- what's wrong with the syntax there??? [and could someone remind me of the 'right' way to test for missing macro args..:)]

On another front, I see in all the examples that there are multiple {}s around logical expressions. Why? For example, I see things like:
If>{{%a% = 4} AND {%b%=7}}
why the extra {}s? wouldn't just
If>{%a% = 4 AND %b%=7}
be sufficient?

Thanks!
/Bernie\

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Tue Jan 11, 2005 1:48 pm

A couple (ok, 3) of things I immediately see, regarding syntax.

If>{(expression) AND (expression)}
It's just "endif", not "endif>".
Let>blah=%Default% (no curlies)

bernie
Junior Coder
Posts: 47
Joined: Sun Sep 22, 2002 4:16 pm
Location: Virginia

Post by bernie » Tue Jan 11, 2005 2:03 pm

Just a minor explanation: what I'm doing is converting a bunch of old scripts to use the neat/new machinery and so that's why some of these questions will seem so stupid..:)
Captive wrote:
If>{(expression) AND (expression)}
I don't understand why you need the interior {}'s -- 'AND' is [as far as i can tell] defined as just another complex expression operator. why do you need the extra sets of {}s?
Captive wrote:

Let>blah=%Default% (no curlies)
Why not? I agree that the curlies are superfluous in that simple situation, but they ought to be OK, no? [sort of a degenerate one-term expression].

I still don't understand why if>{%var%'"} gets me a syntax error...
/Bernie\

User avatar
Captive
Macro Veteran
Posts: 213
Joined: Sun Oct 20, 2002 8:37 pm
Location: Colorado, USA

Post by Captive » Tue Jan 11, 2005 2:23 pm

bernie wrote: I don't understand why you need the interior {}'s -- 'AND' is [as far as i can tell] defined as just another complex expression operator. why do you need the extra sets of {}s?
They're not curlies. The very outer set are. The inner set (which surround the individual expressions) are regular parathesis.
bernie wrote:
Captive wrote:Let>blah=%Default% (no curlies)
Why not? I agree that the curlies are superfluous in that simple situation, but they ought to be OK, no? [sort of a degenerate one-term expression].
Because then the value of your variable would contain the curlies. If you wanted the string to literally contain them, then sure - using them is ok.
bernie wrote:I still don't understand why if>{%var%'"} gets me a syntax error...
I notice that in the help file (and many other examples I've seen), there is actually a space in the expression between the arguments and the operator.

IF>{(%var% = "")}
and
IF>{(%var%="")}
.. may not be the same. (I've not tested this though)

Depending on what you're doing, perhaps the Assigned> or Length> commands may work better?

bernie
Junior Coder
Posts: 47
Joined: Sun Sep 22, 2002 4:16 pm
Location: Virginia

Post by bernie » Tue Jan 11, 2005 5:31 pm

Captive wrote:
bernie wrote:
Captive wrote:Let>blah=%Default% (no curlies)
Why not? I agree that the curlies are superfluous in that simple situation, but they ought to be OK, no? [sort of a degenerate one-term expression].
Because then the value of your variable would contain the curlies.
Actually, it won't: I just tried it and the curlies worked as I expected:


Let>a={"abcdef"}
Let>b={%a%}
MessageModal>%b%

bernie wrote:I still don't understand why if>{%var%'"} gets me a syntax error...
I've done some more testing here and I've got it now: you get a syntax error if you use an unassigned variable in a complex expression.
Captive wrote: Depending on what you're doing, perhaps the Assigned> or Length> commands may work better?
Absolutely -- I was trying to 'convert' some old, pre-"Assigned" code, but that's exactly what I need. Thanks!!!
/Bernie\

Xapti

Post by Xapti » Mon Feb 14, 2005 4:53 am

Hi. I am having great trouble getting any of the Boolean operators working in my If statements...

Here is a sample of code:
Getcursorpos>X,Y
Getpixelcolor>X,Y,PC
if>{(%PC%=0) OR (PC%=10079402))
MessageModal>%X%,%Y% is True, color is %PC%.
else
MessageModal>%X%,%Y% is False, color is %PC%.
endif

I always get the answer
[coordinates] is False, color is 10079402.
or
[coordinates] is False, color is 0.
So ovbiously the var. PC is one of those two values, but the If statement isn't detecting it. I have never sucessfully used any Boolean in an If statement.[/quote]

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Feb 14, 2005 5:43 am

I see two items that look like they need to be corrected:

if>{(%PC%=0) OR (%PC%=10079402)}
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Xapti

Post by Xapti » Mon Feb 14, 2005 7:09 pm

Sheesh. How in the world did I miss that? Oh well whatever, Thanks.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts