Complex Expressions

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
jleuzinger
Newbie
Posts: 7
Joined: Mon Sep 04, 2006 9:05 am

Complex Expressions

Post by jleuzinger » Fri Sep 15, 2006 2:41 pm

Why does this code not work ?

Code: Select all

// Test der String-Funktionen

LET>a={"xyz"}

IF>{Pos("xy",%a%) > 0}
  message>true
ELSE
  message>false
ENDIF



I got an Error-Message: "Error - Subroutine/Label %a%) > 0} Not Found !"

Any help appreciated

regards
Joerg

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Sep 15, 2006 3:44 pm

This would be the way to do it based on the examples in the Help:

Let>a=xyz
Let>IsItThere={if(pos("xy",%a%)>0,"true","false")}
Message>IsItThere

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

Post by Marcus Tettmar » Fri Sep 15, 2006 5:07 pm

Or you could do:

Code: Select all

LET>a={"xyz"}

Let>Expr={Pos("xy",%a%) > 0}
IF>Expr=TRUE
  message>true
ELSE
  message>false
ENDIF
It is just because there is a comma in the expression. You could also do:

Code: Select all

LET>a={"xyz"}
Let>p={Pos("xy",%a%)}
IF>p>0
  message>true
ELSE
  message>false
ENDIF
Or, without complex expressions:

Code: Select all

LET>a=xyz
Position>xy,%a%,1,p
IF>p>0
  message>true
ELSE
  message>false
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?

jleuzinger
Newbie
Posts: 7
Joined: Mon Sep 04, 2006 9:05 am

Post by jleuzinger » Fri Sep 15, 2006 10:21 pm

Thank you very much for your quick help !

My first impression of Macro Scheduler was, that it meets all my needs.
Now I tried to develop some scripts to learn the language.
I tend to write expressions what in Macro Scheduler are called "complex expressions" (perhaps because of my programmers background).
I spent a lot of time finding the correct syntax. Especially Spaces after an if> statement lead to confusing results.

It is just because there is a comma in the expression.
I didn't read an advice in the help.
Are there other constraints in using complex expressions ?

regards
Joerg

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Sep 15, 2006 11:03 pm

If you search through and read the forum you'll see that the characters that are the greatest problem for new users are the comma and the space characters. The comma is a problem because it is the delimiter in the Macro Scheduler functions. The space character is usually a problem for experienced programmers who are used to spaces being unseen items in a line of code. In Macro Scheduler the space character is a valid character and placing it into a function in any location that any other stray character would cause a problem will cause a problem.

Space has its own built in variable since version 8.0. The variable is called by enclosing it in percents... %SPACE%.

Comma does not have a built in variable but when I need to use one in a script other than in normal syntax, I always create the variable "comma" at the top of the script.

e.g
Let>comma=,

In the case of your posted example, since there is a comma required in the POS expression, the If> function interprets everything after the comma as a label. So even if you replaced the "," with "%comma%" it would still fail. Your only option is to break the request down into 2 lines of code as in Marcus' examples or write it as Me_again did. (Me_again's code works but I would never have figured out the proper syntax. Very impressive...)

Hope this helps,
Dick

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Sep 16, 2006 1:09 am

That's very nice but I swiped it almost directly out of the help :)

If you are used to a something like C then some things in macrosheduler can drive you nuts. But the help is good, support from Marcus is great, and once you get a little familiar with it the possibilities are just amazing.

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

Post by Marcus Tettmar » Sat Sep 16, 2006 7:39 am

Me_again wrote:If you are used to a something like C then some things in macrosheduler can drive you nuts.
But if you are used to C you probably don't need Macro Scheduler.

People who are not programmers like Macro Scheduler because it is NOT strongly typed, doesn't insist on delimiters and lets you mix variables and literals.

People who are experienced programmers will find some things about Macro Scheduler annoying. But, then, if you are an expert C++ programmer, you don't really need Macro Scheduler at all.

More expert programmers use VAREXPLICIT, to force a differentiation between variables and literals.

Because strings and variables are not delimited in Macro Scheduler, spaces are treated as any other character. So this:

Let>x = fred

.. will create a variable called "x " which is assigned the value of " fred". I.e. the spaces are included.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Sep 16, 2006 3:00 pm

mtettmar wrote:
Me_again wrote:If you are used to a something like C then some things in macrosheduler can drive you nuts.
But if you are used to C you probably don't need Macro Scheduler.
I very much disagree, different tools for different purposes. Also, I was generically referring to the language. Don't forget that there's a whole universe of C programmers out there who have never needed to write a windows or PC program.

Sorry if my comment came across as though I was knocking macro scheduler, I wasn't. You have an outstanding product and support.

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

Post by Marcus Tettmar » Sat Sep 16, 2006 5:47 pm

No offence taken. Just justifying the differences between C and Macro Scheduler. I just realise that experienced programmers find some of the nuances of Macro Scheduler quirky after lower level, well typed languages.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

jleuzinger
Newbie
Posts: 7
Joined: Mon Sep 04, 2006 9:05 am

Post by jleuzinger » Sun Sep 17, 2006 8:05 pm

I agree with me_again "different tools for different purposes" and I also appreciate the excellent support from Marcus and other "power users".
I don't criticize that MS is an untyped language. Other script languages like Ruby or Python are also untyped languages and nevertheless well-defined and easy to learn.
IMO the biggest source of trouble in MS is, that Spaces have a quite different meaning than in all other languages. This is not very obvious.
But I still don't understand why a Comma enclosed in a {}-Expression should affect the outer (if-)statement.

regards
Joerg

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

Post by Marcus Tettmar » Sun Sep 17, 2006 8:49 pm

The comma separates parameters, and the if statement can take two extra optional parameters. So you need to do this:

Code: Select all

Let>a=xyz
LET>p={Pos("xy",%a%)}
IF>p>0
  message>true
ELSE
  message>false
ENDIF
Or one of the other suggestions provided previously.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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