If no variable then prompt ; how to.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
jnerces

If no variable then prompt ; how to.

Post by jnerces » Mon Mar 10, 2003 3:56 pm

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?

Lumumba

Post by Lumumba » Mon Mar 10, 2003 9:07 pm

How to put the variable to the clipboard as well, and check the clipboards content ..?

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

Post by Captive » Mon Mar 10, 2003 9:15 pm

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

jnerces

Thanks for the reply

Post by jnerces » Mon Mar 10, 2003 10:19 pm

That worked like a charm. Thanks

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