Complex expression documentation

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

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

Complex expression documentation

Post by Bob Hansen » Fri Sep 19, 2008 6:37 pm

Have run into an anomoly with the syntax for complex expressions. Unfortunately I was providing some help without the opportunity to test out first. We finally have a solution, but would appreciate some clarification about the "rules"

This if from the Help File:

Code: Select all

IF>{(%a% = 5) AND (%VarA% = "allen")}
This gives me a syntax error:

Code: Select all

If>{(%ThisRecord%=##EOF##) AND (%FileLine%=2)}
Help is very clear that complex expressions must be surrounded with Braces. When I got syntax error I tried many variations of space characters, quotes. Finally, we found two solutions:

I found that this one is OK, no syntax error:

Code: Select all

If>(%ThisRecord%=##EOF##) AND (%FileLine%=2)
The only difference is NO BRACES!

And my client found that this one is OK, no syntax error:

Code: Select all

If{(%ThisRecord%=##EOF##) AND (%FileLine%=2)}
This contains no ">" character.

Is there some type of exception that needs to be identified?
Is this a problem with Macro Scheduler?
As a minimum, I would suggest that the Help file needs to be corrected?
If ">" should not be used with complex expressions, should be noted in Help and the sample should be corrected.
If Braces should be sliminated, what are the conditions?

Thanks for listening, keep up the great work with Macro Scheduler.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Fri Sep 19, 2008 7:10 pm

Bob,

If you remember to put values in " " which are strings and no " " when the variable or literal is numeric, it will work perfectly evertime. If you are comparing a variable which might be either, then include the " ".

So you first example of :

If>{(%ThisRecord%=##EOF##) AND (%FileLine%=2)}

should be:

If>{(%ThisRecord%="##EOF##") AND (%FileLine%=2)}

I'll test your example of no braces, but I would suspect Macro Scheduler would not compare both conditions.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Complex expression documentation

Post by Marcus Tettmar » Fri Sep 19, 2008 8:27 pm

Bob Hansen wrote:
This gives me a syntax error:

Code: Select all

If>{(%ThisRecord%=##EOF##) AND (%FileLine%=2)}
Should be:

If>{(%ThisRecord%="##EOF##") AND (%FileLine%=2)}

Complex expressions want string delimiters - use quote marks for strings.

That is assuming of course that ThisRecord is a string and FileLine is a number.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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 » Sat Sep 20, 2008 12:31 am

Thanks for the refresher info Marcus. But one confusing thing was not shown in my message. I did change the line to match your solution with the quotes around ##EOF##, but I was still getting syntax error message when I single stepped.

Her are some of the variations I tried:
If>{(%ThisRecord%="##EOF##") AND (%FileLine%=2)}
If>{(%ThisRecord% = "##EOF##") AND (%FileLine%=2)}
If>{(%ThisRecord%="##EOF##")AND(%FileLine%=2)}
If>{(%ThisRecord% = "##EOF##") AND (%FileLine% = 2)}
If>{(%ThisRecord% = ##EOF##) AND (%FileLine% = 2)}
If>{(%ThisRecord%=##EOF##) AND (%FileLine%=2)}
If>{(%ThisRecord%=##EOF##)AND(%FileLine%=2)}
and probably some more.

But now I realize that part of my error messages were coming from the fact that I had done paste/copy on the lines above existing lines but did not bother to comment out the previous bad lines. So I was seeing errors because I was missing EndIf lines for each of the IF lines. Originally I only had the one line with one EndIf statement. It looks like the original problem was that I forgot the quores, and the variations I was trying were giving me error messages for a different reason. Aaargh!

So, in this case, what should have been simple to fix was complicated because I wasn't looking at the whole If block(s). As it turned out, the whole If statement was not finally used due to other program changes.

Thanks again.......
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Complex Expressions

Post by [email protected] » Sun Sep 11, 2011 3:29 pm

I know this is an old chain, but I am have the same problem.
The expression:
If>{(%RP_WINDOWMODE% = "0") AND (%Interact% = "TRUE")}
Gives me a syntax error as does
If>{(%RP_WINDOWMODE% = 0) AND (%Interact% = "TRUE")}
and
If>{(%RP_WINDOWMODE% = 0) AND (%Interact% = TRUE)}
I have reverted to standard expressions but do not understand the problem above.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Sun Sep 11, 2011 8:52 pm

Hi "[email protected]",

Spaces where they are not needed can cause problems... but beyond that, copy the following code and run it:

Code: Select all

//Let>RP_WINDOWMODE=0
//Let>Interact=TRUE

If>{(%RP_WINDOWMODE%=0)AND(%Interact%="TRUE")}
  MDL>expression was true
Else
  MDL>expression was false
EndIf
It errors out for me... and should error out for you.

I believe if either of the variables in that complex expression are not defined, it is going to produce an error. Its too bad the error message does not tell us straight away that Variable %xxx% is not defined... maybe in future these error messages could be improved... Marcus, your thoughts?

So now delete the // in front of the Let> statements so the variables get defined, run it again and now it works with no errors.

You did not post your entire script, but my guess is that when execution falls to your If> statement with that complex expression... either one or both of your variables are undefined. It would be easy to see this... just add these two lines in immediately prior to your If> line in your original script:

MDL>RP_WINDOWMODE
MDL>Interact

Values should be displayed for both.

When dealing with string variables, remember that "TRUE" is not the same as "True". When you use a Let> statement to set a variable, you know exactly what you are setting it to... however when an MS function sets a variable, you don't know what it used unless you check. Make sure you know exactly what it does set it to... and test for that in your expressions.

Also read the following post and note that there are no native boolean variables in Macro Scheduler:
Native Boolean Variables in Macro Scheduler

I hope this helps... take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

[email protected]
Junior Coder
Posts: 25
Joined: Wed Jul 20, 2011 3:07 pm

Post by [email protected] » Mon Sep 12, 2011 2:10 am

Thank you for the help. It turns out that the System Variable, RP_WINDOWMODE was not defined. I expected that a System Variable would be defined with it's default value. Seems strange to me, but now I know. Thank you again for your help.

jpuziano wrote:Hi "[email protected]",

Spaces where they are not needed can cause problems... but beyond that, copy the following code and run it:

Code: Select all

//Let>RP_WINDOWMODE=0
//Let>Interact=TRUE

If>{(%RP_WINDOWMODE%=0)AND(%Interact%="TRUE")}
  MDL>expression was true
Else
  MDL>expression was false
EndIf
It errors out for me... and should error out for you.

I believe if either of the variables in that complex expression are not defined, it is going to produce an error. Its too bad the error message does not tell us straight away that Variable %xxx% is not defined... maybe in future these error messages could be improved... Marcus, your thoughts?

So now delete the // in front of the Let> statements so the variables get defined, run it again and now it works with no errors.

You did not post your entire script, but my guess is that when execution falls to your If> statement with that complex expression... either one or both of your variables are undefined. It would be easy to see this... just add these two lines in immediately prior to your If> line in your original script:

MDL>RP_WINDOWMODE
MDL>Interact

Values should be displayed for both.

When dealing with string variables, remember that "TRUE" is not the same as "True". When you use a Let> statement to set a variable, you know exactly what you are setting it to... however when an MS function sets a variable, you don't know what it used unless you check. Make sure you know exactly what it does set it to... and test for that in your expressions.

Also read the following post and note that there are no native boolean variables in Macro Scheduler:
Native Boolean Variables in Macro Scheduler

I hope this helps... take care.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Sep 12, 2011 6:18 am

Hi "[email protected]",
[email protected] wrote:Thank you for the help. It turns out that the System Variable, RP_WINDOWMODE was not defined. I expected that a System Variable would be defined with it's default value. Seems strange to me, but now I know. Thank you again for your help.
No problem, glad to help.

I ran into this myself a ways back and it seemed odd to me as well. I am only going from memory here (so correct me if I am wrong Marcus) but I believe the reason behind why it works this way is to save time/memory by not automatically defining System Variables that are not often used...?

An easy way to tell which System Variables are created automatically and which aren't... is to use the Debugger. Just single-step through a script and on the first click, the Watch List will show the System Variables that get created every time and what values they are initially set to.

This has started me thinking though. Marcus... perhaps many others have run into this same problem and burned up time trying to figure out why their If> statement complex expressions were erroring out... so I offer the following thoughts:
  1. Perhaps its time to automatically define all System Variables when a script starts up and set them to their default values (as one might expect to be the case). This would seem to follow the principle of least surprise.
  2. Instead of or in addition to 1), if the error message told us "Variable %RP_WINDOWMODE% undefined" then we'd immediately know what the real problem is... and it would also help in cases where its one of our own variables that we haven't defined yet.
  3. Add something in the Help File under Complex Expressions that explains that undefined variables inside a Complex Expression are going to cause an error that says... "unable to parse... etc." though like you have said, you can't put everything in the Help File... and if we had 2) then this is certainly not needed.
  4. Add a "pre-run" process such that when you run (or compile) a script, it checks for the presence of all MS functions and if some are used that do not normally get their associated System Variables defined automatically... then it will define those as well. While this would work, even I think its over-complicated compared to just doing 1).
  5. No change... that's what the forums are for.
Again, all the above is just food for thought... thanks for listening and take care.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Sep 12, 2011 7:44 am

Some of those "system variables" are flags which alter the behaviour of certain commands. They therefore don't need to pre-exist and only need setting if the default behaviour should change. They're referred to as "system variables" by way of documenting them and by way of distinguishing them from user defined variables. But this does not and should not imply that they pre-exist. Nowhere has this ever been suggested.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Sep 12, 2011 3:47 pm

mtettmar wrote:Some of those "system variables" are flags which alter the behaviour of certain commands. They therefore don't need to pre-exist and only need setting if the default behaviour should change. They're referred to as "system variables" by way of documenting them and by way of distinguishing them from user defined variables. But this does not and should not imply that they pre-exist. Nowhere has this ever been suggested.
Thanks for this reply Marcus... it makes perfect sense now why they do not pre-exist... i.e. we only need to manually set them if we want other than the default behavior of the Function we're using.

However 2) still makes sense to me... an improved error message... if that could be done, it would be helpful... maybe a wish list item?

Thanks for listening and take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

Complex Expressions

Post by liveitupmore » Sat May 04, 2013 3:32 am

I wrote and compiled a script in 2010 which worked fine.

Last week I made some minor changes and recompiled using V14.0.4 and the script doesn't work. I have an error message "A not appropriate"

Here is a snapshot of the script that fails.

Let>line=1,"A","D","GNS"," "," "," "," ","1988"," ","20130430","0724","R2V9"
Separate>line,%comma%,var
IF>{(%var_2%="D")AND(%var_4%"TURNOVER")}
Let>PartNum=
endif

Any suggestions.

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Post by PepsiHog » Mon May 06, 2013 2:07 am

@liveitupmore

Just a tip. Your question is at the bottom of another post. I get that it deals with complex expressions, but a new post by you would likely be answered quicker.

Anyway. How can "D" ever be var_2 when it is the third(3) segment?

1> 1
2>"A"
3>"D"

If you meant var_3, here is a possibility.

Code: Select all

let>PartNum=x
let>comma=,
let>quote="
Let>line=1,"A","D","GNS"," "," "," "," ","1988"," ","20130430","0724","R2V9"
Separate>line,%comma%,var
//IF>{(%var_3%="D") AND (%var_4%<>"TURNOVER")}
if>var_3="D"
   if>var_4<>"TURNOVER"
     Let>PartNum=
   ENDIF
endif
mdl>%PartNum% (%var_3%)
The problem with complex expression is that it expects quotes around literals. And I can't figure out how to place quotes in quotes. But there is probably a way. I just don't know how.

Hope this helps,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

Post by liveitupmore » Mon May 06, 2013 4:56 am

Thanks PepsiHog,

I agree with your suggestion and had thought that myself, however you should be able to do it as a complex expression so I thought I would ask.

Line 1 was just a sample, it is data from a text file read line by line and other lines have "D" in var_2.

That was my biggest problem how to quote quotes.

I'll leave it for a week or so to see if I get more suggestions, if not I'll start a new post.

Liveitupmore

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue May 07, 2013 8:54 am

You need to double quote quotes. So this works:

Code: Select all

Let>line=1,"A","D","GNS"," "," "," "," ","1988"," ","20130430","0724","R2V9"
Separate>line,%comma%,var
IF>{("%var_2%"="""D""")AND("%var_4%"<>"""TURNOVER""")}
  Let>PartNum=
endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

liveitupmore
Junior Coder
Posts: 22
Joined: Wed Nov 16, 2005 3:58 am
Location: Gold Coast, Australia

Post by liveitupmore » Tue May 07, 2013 10:45 am

Many thanks

Alistair :D

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