Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
wells50
- Newbie
- Posts: 14
- Joined: Sat Mar 04, 2006 9:58 pm
- Location: Edina, Minnesota USA
-
Contact:
Post
by wells50 » Sat Mar 11, 2017 2:54 pm
When a compiled macro runs, sometimes it needs to check to see if a Command Line Parameter is present. Here is some code that illustrates how to check for a command line parameter:
Code: Select all
// COMPILE_OPTS|c:\programs\test.exe||CONSOLE=0|INCLUDES=1||RUNTIMES=1|BMPS=1
// Test for presence of a command line parameter
// To test with a parameter, at a Command Prompt enter: test /vtest=something
// To test without a parameter, just run test.exe
MidStr>%vtest%,1,1,vFirstCharacter
If>%vFirstCharacter%=%
// If the command line parameter, vtest, was not present, %vtest% will not
// yet be a variable and will be seen as a string with % as the first character.
Let>vtest=
// By setting the variable to nothing (empty), you avoid having the string %vtest%,
// including the percent signs, appear when your program checks for the presence
// of the command line parameter later on.
MDL>There is no parameter value for vtest. Here it is: %vtest%
Else
MDL>Here the parameter, vtest: %vtest%
Endif
Perhaps there is some much more elegant way to perform the check. If so, I welcome an alternative!
Wells H. Anderson
Active Practice LLC
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Sun Mar 12, 2017 12:22 pm
Hi,
Any reason why you wouldn't just use the Assigned function:
Code: Select all
Assigned>vTest,bGotvTest
If>bGotvTest=FALSE
Let>vTest=some default value
Endif
-
wells50
- Newbie
- Posts: 14
- Joined: Sat Mar 04, 2006 9:58 pm
- Location: Edina, Minnesota USA
-
Contact:
Post
by wells50 » Mon Mar 13, 2017 4:04 am
Excellent! I hadn't known about the Assigned function. It is perfect for checking the existence of a variable assigned by the command line or otherwise. Thank you!
Wells H. Anderson
Active Practice LLC
-
mightycpa
- Automation Wizard
- Posts: 343
- Joined: Mon Jan 12, 2004 4:07 pm
- Location: Vienna, VA
Post
by mightycpa » Sat Mar 18, 2017 11:22 pm
I didn't remember it either, even though I used it just the other day. First place I looked was in Help, under "Using Variables."
Suggest you add it in there too.
Here was my workaround:
Code: Select all
Let>IGNOREERRORS=1
ConCat>undeclared_var,
Length>undeclared_var,uvLen
If>uvLen=0
...
Assigned is MUCH better.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey