![]() |
|
VBScript Tutorial #3 In this tutorial, I'll show how the computer can appear to be a bit more intelligent, able to make decisions based on input and modify it's output. This is achieved using the IF statement. I won't be repeating the entire text file as in previous tutorials so you will need to read them first. Here then is a simple IF script:- Option Explicit MyInput =
InputBox("Enter a name", "Name") Dim MyVar Now a message will be displayed no matter what is input. Note that an error condition will still occur even if the word Nick or NIck (or any other upper/lower case mixture) is input. To get around this, use the command LCase. Replace the following line:- MyInput =
InputBox("Enter a name", "Name") MyInput = LCase(InputBox("Enter
a name", "Name")) So now it is possible to show you another MsgBox function which will prove useful in the future. It looks like this. Option Explicit When run, the message box will display the return value of the MsgBox function which in this case will either be 1 or 2 depending on the button pressed by the user. This can be used as follows. Option Explicit So now, it will be possible to ask the user wether to carry out some operation or not (like overwriting an existing file for example) without resorting to text input but instead using only a single mouse click. Have a play with these programs and see if you can add your own variations. The next tutorial will be a little more taxing than this one as we'll be investigating loops. Please eMail me at: nickjc@nickjc.co.uk if you need help |
|