Undefined variables

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Bob

Undefined variables

Post by Bob » Thu Jun 10, 2004 7:15 pm

OK, this must be a basic question but I've been looking high and low for the answer.

I'm calling a script from a command-line and passing some parameters using the following syntax:
/command_line_param=foo

I want to ensure that all the parameters get passed correctly. However, I cannot seem to check the parameter using this syntax:
If>%command_line_param%="",MYLABEL
Or:
If>command_line_param="",MYLABEL

I want to warn the user if a necessary parameter isn't set.

I thought that maybe it uses some JavaScript or Java syntax, so I tried:
If>%command_line_param%=undefined,MYLABEL
And:
If>%command_line_param%=null,MYLABEL

Interestingly enough, the %command_line_param% gets resolved to:
%command_line_param%

Unfortunately, this is not helpful at all as the following would work but not work:
If>%command_line_param%=%command_line_param%,MYLABEL

Hopefully this is very easy. I come from a C/Java background so this script syntax is just killing me.

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 Jun 10, 2004 8:19 pm

Make sure that the destination script being called on the command line already has those parameters defined before the IF> statement.

Can you show the exact command line with parameters that you are using?
And also provide the beginning of the script being called, up to and including the IF> statement.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Guest

Post by Guest » Thu Jun 10, 2004 8:40 pm

>>>Make sure that the destination script being called on the command line already has those parameters defined before the IF> statement. <<<

Errr. That's the whole point. These variables are supposed to be defined in the command-line or a BAT script but there's no guarantee. If they are not, then I want to bring up a dialog warning the user, write to a log, etc. However, I can't seem to find a way to check if a variable wasn't defined.

For example, imagine that you're designing an automation script. As soon as you start it, you want it to present the user with a dialog that asks for the parameters. However, if those parameters were ALREADY specified in the command-line then it should do it's job and not bring up any dialogs. The problem is that there doesn't seem to be a way to check if the variables were defined already or if the variable is in an undefined state.

Maybe I'm asking this product to do something that it wasn't designed to do.

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 Jun 10, 2004 9:14 pm

I suspect that you may not be including the full path and the "scp" portion of the macro file name.

Or this is also a possibility: Note that the empty parameter is "nothing", not a blank string like "".
IF>%one%=,Label is correct, not IF>%one%="",Label

The following scripts work OK for me.

Script: Passing Parameters Sender
//This script it to send a parameter to another script.
//The test parameter in the other script is named "one"
Macro>Q:\Data\MacroScheduler\Test\Passed Parameters Receiver.scp /one=GOOD
Script: Passing Parameters Receiver
//This script is intended to be called by another passing in values.
//If the values are missing, then user will be prompted for value

If>%one%=,Missing1
Message>%one%
Goto>End

Label>Missing1
Input>oneprompt,Please enter missing value
Message>%oneprompt%

Label>End
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Guest

Post by Guest » Thu Jun 10, 2004 9:53 pm

Thanks for the insite. Now I know how it's supposed to work. I tried using the "Macro>" and that's fine. However, it doesn't pass from the command-line. This is how I launch the macro:

"C:\Program Files\MJT Net Ltd\Macro Scheduler\msched.exe" C:\Automation\test.scp

The above is actually one line.

The test.scp contains:
If>%one%=,Missing1
MessageModal>%one%
Goto>End

Label>Missing1
Input>oneprompt,Please enter missing value
Message>%oneprompt%

Label>End


The dialog always shows up with "%one%" inside it.

As expected, the following line with the variable defined works. The dialog displays the contents of the variable:

"C:\Program Files\MJT Net Ltd\Macro Scheduler\msched.exe" C:\Automation\test.scp /one=foo

I guess as a work-around, I can use the "Macro>" but it would be interesting to find out if the above can be reproduced by someone else.

Thanks for your support.

Lumumba

Post by Lumumba » Thu Jun 10, 2004 11:20 pm

Well I'm still waiting for response from MJTNet support/Marcus Tettmar on a parameter issue which is equivalent to yours (the difference is that it should work with a compiled script).

The standard with DOS, you can use up to 10 (0,1,2,3,...,9) parameters with an exe. Unfortunately MSched won't work with this system based variables.

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 » Fri Jun 11, 2004 12:18 am

OK... I see the problem I also did some testing with batch files and with Run Program> and Macro> variations.

Summary:.....this looks like a BUG to me. The documentation is quite clear that parameters can be passed on the command line.

OR.......

Wait a minute. The distinction is whether or not a parameter's value is passed, not if a parameter was passed!

1. This is GOOD: Macrocommand scriptname /parameter=Value
2. This is GOOD: Macrocommand scriptname /parameter=
3. This FAILS: Macrocommand scriptname

I was testing the IF statement using format 3 which actually passes no parameter. The IF> test does not prompt for input, conclusion was that it failed.

Format 2 passes a parameter, but the value is missing. That format does work correctly. The IF> test does prompt for input.

So if a parameter is not passed, it cannot be considered as missing. It is only wrong if the passed value is missing.

So the testing needs to be for the value of the parameter on the right hand side of the "=".

So if you want to run as a command, let me suggest that you put the command in a batch file that already has the parameter syntax defined. Result would look something like this:

batchfile name = macname.bat. Contents = :
macrocommand scriptname /parameter=%1
The command to run the macro with the parameter would be "macname.bat Value." If Value is missing, then the batch file itself could test for %1, or let the called script test for it as we have tried in this discussion.

So I reverse my thinking, I do not think that this is a bug.
You can test to see if a parameter's "passed value" is missing. But this might be a good request as an enhancement request for the future. Be nice to have the ability to test if no parameter was passed at all.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Bob

Undefined variables when calling script from command-line

Post by Bob » Fri Jun 11, 2004 2:05 pm

I would say that this is definitely a bug. Using a BAT file is a work-around and not a solution. For example, I may want to create an EXE out of my script. I would need to include the BAT file as a work-around, to avoid this problem. Unfortunately, there is no guarantee that the user will use the BAT file instead of the EXE.

I'll search this site to see where I can enter this as a bug. I'd be interested in hearing the official response to this problem.

Thanks for all your help.

Bob

Post by Bob » Fri Jun 11, 2004 6:31 pm

Hey Guys,

I have a work-around that is more palatable. I thought I'll share it with you as it may help.

Remember that the problem is specific to undefined variables that were not specified in the command-line. As I understand, there is no way to check for them. Fortunately, we can use VBScript to help us. Here is the code I use:

Start of "isDefined.scp>>>
//
// isDefined
//
// Function to see if a variable is defined or not
//
// This is useful if you're calling the script from the command-line and need to know
// if the user specified the required parameters on the command-line before continuing
//

VBSTART
Function isDefined (myVariableString)
' Check the first character of the string
myNumber = Asc(myVariableString)
' If the first character is a '%' then the variable was probably not defined
' The '%' character is ANSI code 37
If myNumber = 37 Then
isDefined = "false"
Else
isDefined = "true"
End If
End Function
VBEND

// Uncomment the following line to define the "one" variable
// Let>one=foo
VBEval>isDefined("%one%"),isDefinedTemp
If>%isDefinedTemp%=false,Error
Goto>End

Label>Error
MessageModal>Not all parameters defined (bring up dialog that will allow the user to specify them)
Goto>End

Label>End
<<< End of isDefined.scp

This works. I test it like this:
msched.exe C:\Automation\isDefined.scp
and
msched.exe C:\Automation\isDefined.scp /one=foo

I'm a beginning Macro Scheduler user so please forgive any stupid mistakes. All comments welcome.

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 » Fri Jun 11, 2004 8:09 pm

Good work Bob, very creative.

You are right here:
This works. I test it like this:
msched.exe C:\Automation\isDefined.scp
and
msched.exe C:\Automation\isDefined.scp /one=foo

but it fails when you test this:
msched.exe C:\Automation\isDefined.scp /one=
Result is an error message:
Microsoft VBScript runtime error:5
Invalid procedure call or argument: 'Asc"

Get that fixed and you have created a keeper! :D
=====================================

:idea: Also, just for general reference, if you need to use long string with spaces on the command line, you need to surround each segment with double quotes. But it is good to clarify that the parameter "/one=foo" is in its own segment. Do not include it in the same segment as the macro script being called.

This is Good:
"c:\long path\msched.exe" "C:\Automation\isDefined.scp" /one=foo
This is No Good:
"c:\long path\msched.exe" "C:\Automation\isDefined.scp /one=foo"
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
aliteralmind
Newbie
Posts: 14
Joined: Sun Jan 17, 2010 4:53 pm
Location: Philly
Contact:

Post by aliteralmind » Wed Nov 16, 2011 10:49 pm

Bob!

I finally am diving into Macro Scheduler.

Annoyed I can't call macros with key-strings (like by typing runmymacro` --and executing from another program, via the command-line, is intolerably slow), but otherwise really pleased so far.

Nice to see you hanging around here :)
:' )
aliteralmind

MY BOYS!
http://brothers.jeffyepstein.com

User avatar
aliteralmind
Newbie
Posts: 14
Joined: Sun Jan 17, 2010 4:53 pm
Location: Philly
Contact:

Post by aliteralmind » Wed Nov 16, 2011 11:15 pm

A little heartache I can spare others:

Using this

Code: Select all

Macro>%sMACDIR%generic\ci_missing_rqd_param.scp /sMName=key_modified /sPName=k /sValue=%k%
Worked fine.

Using this

Code: Select all

Macro>%sMACDIR%generic\ci_missing_rqd_param.scp /sMName=key_modified/sPName=k/sValue=%k%
Did not. It caused b to equal FALSE:

Code: Select all

Assigned>sPName,b
:' )
aliteralmind

MY BOYS!
http://brothers.jeffyepstein.com

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 Nov 17, 2011 3:07 am

For aliteralmind:

Is Jeffy lost? What are you doing in this neighborhood?

I haven't heard from you in years. And if you look closely, I have not been here very much recently. Glad to see you jumping into Macro Scheduler, a great product, fantastic tools. I may be back in the saddle again in a short time. Best wishes and good luck!
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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