If no variable then prompt ; how to.
Moderators: JRL, Dorian (MJT support)
If no variable then prompt ; how to.
I create my scripts to recieve variables at the command line which works great, but it makes it hard to debug. Isthere a way to check for a passed variable and if it is not there to prompt for one?
Owwie. I tried a few ways to solve this one, and had to use VBScript in the end.
If I had not previously declared %sName%, then it would literally be the string %sName%.
I hope the following helps you find a way to solve your problem. Unfortunately, I had to code in so that if the string itself is "%sName%", then it thinks it's 0 characters... so the routine isn't very portable, and if you edit the names of the variables, you have to also edit the function.
Here's my example:
Rem>------------------------------
Rem>Prompt for a name if the "sName" variable is blank.
Rem>See the command "Macro" in the help file to see
Rem> how to pass variables from one macro to another.
Rem (Example: "Macro>NameCheck.scp /sName=Bill")
Rem>------------------------------
VBSTART
Function GetNameLen(sNameToCheck)
If sNameToCheck = "%sName%" then
GetNameLen = 0
Else
GetNameLen = Len(sNameToCheck)
End If
End Function
VBEND
Rem>------------------------------
Label>CheckNameLength
Rem>How many characters is the %sName% variable.
VBEval>GetNameLen("%sName%"),nName
Rem>If %nName% is 0 characters go to the 'PromptName' label.
If>%nName%=0,PromptName
Rem>------------------------------
Rem>The name is not blank, show a message
MessageModal>The name supplied was %sName%%CRLF%%nName% characters
Goto>TheEnd
Rem>------------------------------
Label>PromptName
Input>sName,Please enter your name
Rem>Go back and check the length of this name
Goto>CheckNameLength
Rem>------------------------------
Label>TheEnd
If I had not previously declared %sName%, then it would literally be the string %sName%.
I hope the following helps you find a way to solve your problem. Unfortunately, I had to code in so that if the string itself is "%sName%", then it thinks it's 0 characters... so the routine isn't very portable, and if you edit the names of the variables, you have to also edit the function.
Here's my example:
Rem>------------------------------
Rem>Prompt for a name if the "sName" variable is blank.
Rem>See the command "Macro" in the help file to see
Rem> how to pass variables from one macro to another.
Rem (Example: "Macro>NameCheck.scp /sName=Bill")
Rem>------------------------------
VBSTART
Function GetNameLen(sNameToCheck)
If sNameToCheck = "%sName%" then
GetNameLen = 0
Else
GetNameLen = Len(sNameToCheck)
End If
End Function
VBEND
Rem>------------------------------
Label>CheckNameLength
Rem>How many characters is the %sName% variable.
VBEval>GetNameLen("%sName%"),nName
Rem>If %nName% is 0 characters go to the 'PromptName' label.
If>%nName%=0,PromptName
Rem>------------------------------
Rem>The name is not blank, show a message
MessageModal>The name supplied was %sName%%CRLF%%nName% characters
Goto>TheEnd
Rem>------------------------------
Label>PromptName
Input>sName,Please enter your name
Rem>Go back and check the length of this name
Goto>CheckNameLength
Rem>------------------------------
Label>TheEnd