")
will display a prompt on the screen when the script is run, asking for some
text to be typed. When you enter some text and click OK, the script places
the text you??™ve typed into the variable MyName and continues on to the next
command.
Now, collecting and rearranging information does no good without the ability
to spit out a result. The versatile MsgBox function allows you to display a
simple message, as follows:
MsgBox "Hello, Hello Again."
Combining the principles covered so far, consider the following code:
MyAge = InputBox("Please type your age.")
NewAge = MyAge + 5
MsgBox "In 5 years, you will be " & NewAge & "."
The first line does two things: it first asks the user to type something, and
then assigns the typed text to the variable MyAge. The second line creates a
new variable, NewAge, assigns the user??™s input to it, and adds five. Note the
lack of any error checking in this example: if one enters something other
than a number, this code will cause a WSH error, and the script will end
early. The third line then uses the & operator to concatenate (glue together) a
text string to the NewAge variable and displays the result in a message box.
Build a VBScript Script | 517
Scripting and
Automation
Notice that plain text is always enclosed in quotation marks, but variable
names are not. If you were to enclose the NewAge variable in quotation
marks, the script would simply print out the text NewAge instead of whatever
value is stored in the variable.
Pages:
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719