pos function question

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Kidada
Newbie
Posts: 3
Joined: Thu Dec 30, 2004 4:15 pm
Location: Germany

pos function question

Post by Kidada » Thu Dec 30, 2004 4:22 pm

Maybe a beginners question:

Why is

Let>UseAltS={ If( Pos("-UseAltS", %COMMAND_LINE%) = 0 , 0, 1) }

always giving me a "Incorrectly formed Parameters" Message (twice) and then a "Error Parsing Expression"?

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

Post by Captive » Thu Dec 30, 2004 6:34 pm

Well the answer to your exact question is: Because it's an incorrectly formed expression.

If I break down what you've put:
Let>UseAltS={ If( Pos("-UseAltS", %COMMAND_LINE%) = 0 , 0, 1) }

Pos("-UseAltS", %COMMAND_LINE%) should return an integer

to:
Let>UseAltS={ If( interger = 0 , 0, 1) }

Then perhaps you can see why this is incorrect. Are you trying to use an "if" command, and send it to a label called "0" if the result is 0, and "1" otherwise? If so, it shouldn't be on the right side of a "Let>" command.

What exactly are you trying to assign to the variable "UseAltS" ?

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 » Thu Dec 30, 2004 10:37 pm

Ignoring other syntax issues, you should also be careful not to put unwanted space characters before/after commas, equal signs, etc. when defining parameters.

This:
Let>UseAltS={ If( Pos("-UseAltS", %COMMAND_LINE%) = 0 , 0, 1) }
is probably wrong, and not the same as this:
Let>UseAltS={If(Pos("-UseAltS",%COMMAND_LINE%)=0,0,1)}
which is probably more correct.
Macro Scheduler is very literal when it comes down to compiling the command lines. It assumes that spaces are intentional and they become part of the elements when the lines are parsed and compiled.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Kidada
Newbie
Posts: 3
Joined: Thu Dec 30, 2004 4:15 pm
Location: Germany

Post by Kidada » Sun Jan 02, 2005 5:33 pm

Folks,

Many thanks for your efforts. Only, It's not really solving the question or I am just not getting it.

The story behind the problem is: My macro helps me on my home and my office machine. At home, I have to use an alternative way to make my application do, what I want by using a number of ALT-S keystrokes instead of a mouse action. To be able to use the same macro in both environments, I intended to use the command line. If my command line for the exe version of the macro would be "c:\mymacro.exe -UseAltS", I could assign the value 1 (integer) to my variable UseAltS and later in the code do a conditional jump (the latter already works).

So, what I assumed to be codeing was based on the understanding that Pos("-UseAltS", %COMMAND_LINE%) does return an integer of 0 if the string "-UseAltS" was not on the command line and any value larger that 0 if it was.

Does that help someone to help me out?

Kidada

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

Post by Captive » Sun Jan 02, 2005 6:06 pm

It seems the If>{Pos(...)} expression always returns false.

The following appears to work, although during debugging I would regularlly get an error when using COMMAND_LINE.

Let>nPos={Pos("-UseAltS",%COMMAND_LINE%)}
If>nPos=0
Let>UseAltS=0
Else
Let>UseAltS=1
EndIf


May I suggest you check out the ability to use the command line like this:
/USEALTS=1

Then in your code, the variable %USEALTS% will already be assigned to 1
(You can then probably add a few lines like)

Assigned>USEALTS,WasParamGiven
If>%WasParamGiven%=FALSE
Let>USEALTS=0
EndIf

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

Post by support » Sun Jan 02, 2005 8:23 pm

Or do:

Let>p={Pos("-UseAltS",%COMMAND_LINE%)}
If>p>0
etc
Else
etc
Endif

Or:

Position>-UseAltS,COMMAND_LINE,1,p
If>p>0
etc

Or the If line can be:
If>{%p% > 0}
MJT Net Support
[email protected]

Kidada
Newbie
Posts: 3
Joined: Thu Dec 30, 2004 4:15 pm
Location: Germany

Post by Kidada » Wed Jan 05, 2005 7:21 pm

Captive wrote:
It seems the If>{Pos(...)} expression always returns false.

...

May I suggest you check out the ability to use the command line like this:
/USEALTS=1

EndIf
Captive, thank's a lot! Using /USEALTS did work. Where is that documented? Even now knowing about it I could not find it.

>> It seems the If>{Pos(...)} expression always returns false.

Is that a bug in MS?

Kidada

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

Post by Captive » Thu Jan 06, 2005 1:58 am

Kidada wrote: Captive, thank's a lot! Using /USEALTS did work. Where is that documented? Even now knowing about it I could not find it.
Command Line (Command line options) ...
Kidada wrote:>> It seems the If>{Pos(...)} expression always returns false.

Is that a bug in MS?
Nope. There's nowhere that even suggests If() will work as a function inside a complex expression.

Guest

Post by Guest » Thu Jan 06, 2005 9:57 am

Captive wrote:
Kidada wrote: Captive, thank's a lot! Using /USEALTS did work. Where is that documented? Even now knowing about it I could not find it.
Command Line (Command line options) ...
Thank's Again. As my impressions of the tool are very fresh and I had this problem, I would like to suggest to more clearly separate the documentation between the "programmers docs" and the "how to use, install and register the application MS as such". There are several references to the MS application, which deal with simmilar topics, relevant for development. Would have helped me.

And just that you get me right -- MS is a very noice tool.

Kidada

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