function Pos(Substr: string; S: string): Integer

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

function Pos(Substr: string; S: string): Integer

Post by armsys » Mon Feb 07, 2005 2:43 pm

I have exhausted all combinations of possible VALID parameters in vain. Has anyone succeeded in calling the function? Please help. Thanks.

For example, Let>h={Pos(AW,PC_AW)} will fail.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 3:00 pm

As per the documentation variables in complex expressions must be encased in % symbols (otherwise the complex expression parser is unable to determine that they are variables):


Let>AW=R
Let>PC_AW=FRED
Let>h={Pos(%AW%,%PC_AW%)}

H becomes 2.
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 3:01 pm

Or, if you meant these to be literal strings then, again, as the documentaion says, be sure to quote strings with double quote char:

Let>h={Pos("AW","PC_AW")}

h would equal 4
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Feb 07, 2005 3:48 pm

Hi Support,

Thanks again for your clarification. On the other hand, the online help indicates it's a semicolon, not a comma as shown in your 2 sample scripts.

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 07, 2005 3:57 pm

Good clarification. Would be good examples to include in the Help documentation.

(See User Defined Help).
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 3:58 pm

The semicolon is used in the function definition to separate different items. E.g.:

function Copy(S: string; Index, Count: Integer): string

Note that Index and Count are separated by a comma. S is separated from the rest by a semicolon because it is a string. These function definitions include the type too. The definition for Pos is :

function Pos(Substr: string; S: string): Integer

And could equally have been written:

function Pos(Substr, S: string): Integer

This format is quite common in program language documentation to define the function but I concede that it is a departure from basic syntax used in Macro Scheduler's help for regular commands. Due to the nature of complex expressions we used this more standardised syntax for the documentation. Perhaps we should add a paragraph to further explain what this all means.

In short:

1) Always use a comma between variables in the actual program code.
2) In complex expressions use quote markes ("..") around strings.
3) In complex expressions Use % symbols around variables.

You can see why it is important to distinguish between strings and numerics in the documentation for complex expressions. This has not been necessary for regular commands. Since there is a need to distinguish between type the function definitions get a little more complex and it could be far more confusing if only commas were used.

Sorry for the confusion. It gets harder and harder to write documentation that everyone can understand all the time.

We are, and have always been, open to offers from anyone who thinks they could do a better job, but no offers have ever been forthcoming.

[/b]
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 4:03 pm

Just in case you have missed the correct section in the documentation, info on Complex Expressions can be found here:

http://www.mjtnet.com/OnlineHelp/index. ... ssions.htm

(identical to what is in the help file). Note the very first paragraph:

"In Macro Scheduler all complex functions should be contained within curly braces ("{" and "}"). Variables should be enclosed within % symbols and literal strings should be enclosed within double quotes ("). "

I have made a note to add a sentence to the effect that parameters must be separated by commas.
MJT Net Support
[email protected]

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 07, 2005 4:22 pm

We are, and have always been, open to offers from anyone who thinks they could do a better job, but no offers have ever been forthcoming.
Please see my earlier reference to User Defined Help.

This would allow each of us to provide our own examples using script lines that are meaningful to our own applications. Takes some of the burden off your back to write something that everyone can understand. We could then provide ourselves with the interpretation that makes sense to us.

In all fairness though, most of the Help documentation is well done. Thanks for the hard efforts to please all of us.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 4:25 pm

This is a good idea. We're eagerly (nervously?) awaiting the Longhorn beta, within which is an entirely new XML based help system which may offer a nice way to do this. To avoid potential rework we will wait until we have reviewed this thoroughly before changing the current help system.
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Feb 07, 2005 4:31 pm

Hi Bob,

The user defined help may be a sound idea; however, it's not possilbe in the HTML-based CHM format. The only possibility is to convert it to PDF format. Correctly me if I'm wrong.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Feb 08, 2005 10:00 am

2 more last questions on Complex Expressions:

1. Do Complex Expressions support Macro Scheduler ARRAY, both a whole array and an element?
For example, is it a valid Complex Expressions: Let>h={Pos("AW",USERS[1])} ?
By whole array, I mean operations such as sum and average on ALL elements in an array.

2. Any sample script for function If(Condition: Boolean, TrueResult, FalseResult): ResultType ?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Feb 08, 2005 10:34 am

armsys wrote:1. Do Complex Expressions support Macro Scheduler ARRAY, both a whole array and an element?
For example, is it a valid Complex Expressions: Let>h={Pos("AW",USERS[1])} ?
By whole array, I mean operations such as sum and average on ALL elements in an array.
Yes, on elements:
Let>User[1]=ARMSTRONG
Let>User[2]=BOB
Let>User[3]=CYBERCITIZEN
Let>h={Pos("E",%User[3]%)}

No, not on whole arrays.
armsys wrote:2. Any sample script for function If(Condition: Boolean, TrueResult, FalseResult): ResultType ?
Let>User[3]=CYBERCITIZEN
Let>h={Pos("E",%User[3]%)}
Let>x={if(%h%>0,"yes","no")}

This sets x to yes if E appears in User[3]. Clearly in the case above E appears in CYBERCITIZEN so it's position is positive. Therefore in the if line x is set to yes. x would equal no if User[3] was set to a value that did not contain an E.
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Feb 08, 2005 10:55 am

Hi Support,

Now it's perfectly clear. Prior your revelation, no one in the entire universe could have deciphered correctly that Let>h={Pos("E",%User[3]%)} is a valid complex expression.

BTW, I'm also surprised by my discovery of an undocumented feature. While experimenting new functions and commands in Macro Scheduler, I found that, for example, Goto>Array[3] is supported by Macro Scheduler.

Thanks a lot. Happy Chinese New Year!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Feb 08, 2005 11:23 am

armsys wrote:Now it's perfectly clear. Prior your revelation, no one in the entire universe could have deciphered correctly that Let>h={Pos("E",%User[3]%)} is a valid complex expression.
I dearly hope that isn't the case. I have already pointed you in the direction of the documentation which states clearly:

"In Macro Scheduler all complex functions should be contained within curly braces ("{" and "}"). Variables should be enclosed within % symbols and literal strings should be enclosed within double quotes (")."

So let's look at the example again:

Let>h={Pos("E",%User[3]%)}

Ok, we have curly braces around it. Good, that's what the documentation says. E is a literal string so it is enclosed in quotes as the help says. User[3] is a Macro Scheduler variable. So we'll put it in % symbols as the documentation says. Excellent. What am I missing?
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Feb 08, 2005 12:34 pm

Hi Support,

The issue here isn't about the abstract generalization. Rather, it's about the lack of samples. Of course, by now everyone could grasp the {} things and the %% things, thanks to your extended elaboration.

Thanks again.

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