Undefined variables
Moderators: Dorian (MJT support), JRL
Undefined variables
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.
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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!
Bob
A humble man and PROUD of it!
>>>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.
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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
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
Script: Passing Parameters Receiver//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
//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!
Bob
A humble man and PROUD of it!
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.
"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.
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.
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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 = :
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.
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 = :
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.macrocommand scriptname /parameter=%1
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
A humble man and PROUD of it!
Undefined variables when calling script from command-line
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.
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.
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.
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.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Good work Bob, very creative.
You are right here:
but it fails when you test this:
Microsoft VBScript runtime error:5
Invalid procedure call or argument: 'Asc"
Get that fixed and you have created a keeper!
=====================================
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:
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:
Result is an error message:msched.exe C:\Automation\isDefined.scp /one=
Microsoft VBScript runtime error:5
Invalid procedure call or argument: 'Asc"
Get that fixed and you have created a keeper!
=====================================
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:
This is No Good:"c:\long path\msched.exe" "C:\Automation\isDefined.scp" /one=foo
"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!
Bob
A humble man and PROUD of it!
- aliteralmind
- Newbie
- Posts: 14
- Joined: Sun Jan 17, 2010 4:53 pm
- Location: Philly
- Contact:
- aliteralmind
- Newbie
- Posts: 14
- Joined: Sun Jan 17, 2010 4:53 pm
- Location: Philly
- Contact:
A little heartache I can spare others:
Using this
Worked fine.
Using this
Did not. It caused b to equal FALSE:
Using this
Code: Select all
Macro>%sMACDIR%generic\ci_missing_rqd_param.scp /sMName=key_modified /sPName=k /sValue=%k%
Using this
Code: Select all
Macro>%sMACDIR%generic\ci_missing_rqd_param.scp /sMName=key_modified/sPName=k/sValue=%k%
Code: Select all
Assigned>sPName,b
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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!
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!
Bob
A humble man and PROUD of it!