Script 1
Aim: Make 'Hello World' appear on screen.
Step 1:
Open up notepad and paste in the following test
Code: Select all
MsgBox ("Hello World!")
Save the file as 'script1.vbs and run it.
All done! You should see 'Hello World' written on the screen now.
So... how did that work? Basically, the 'MsgBox' command tells the Windows Script Host, or WSH as I will referr to it by that the text enclosed in brackets and quotes will appear as a text box. So, by changing the text you can make anything appear in the text box.
Now... on to Script 2
Aim: Make a box appear that will ask for your name then reply with a nice message about the pesons name.
Step 1:
Paste the following text into notepad
Code: Select all
Name = InputBox ("What is your name?")
MsgBox ("Hello there "&Name)
Save the file as script2.vbs and run it!
Okay, so it should have replyed saying hello there, then the name that you entered in. Lets see how that worked. For the first line, 'InputBox' is the command that tells the WSH to make a box appear that you can write in. The reason that I put 'Name' there is so that I could referr back to it later. In line two, the text will change depending on whatever is typed in on line one. You can name a variable, (I called mine 'Name'), whatever you want. As long as when you want to enter the text you make sure that it matches up. Please note how I went "Hello there "&Name". You enter the text you want with a space at the end, then ", then &+variable name.
Script 3
Aim: Exactly same as script 2 but with more variables.
I am just going to give you the code for this one. It is very similar to script 2 but with more variables. Edit it yourselves and add more content.
Code: Select all
Name = InputBox ("Hello there, what is your name?")
MsgBox ("WOW! Really? I have always thought that a really good name is "&Name)
Age = InputBox ("What is your age?")
MsgBox ("I remember having fun when I was "&age)
FavThing = InputBox ("What is your favourite thing to do in the weekend?")
MsgBox ("Cool! I love doing "&FavThing)
Aim: For a message to appear insulting everyone except the 'master name'
Code: Select all
Name = InputBox ("What is your name?")
If Name = ("Frederick") Then
MsgBox ("You are L33T Frederick!")
Else MsgBox ("You are n00b "&Name) End If
Change the names so that they are nice to you and have a play with the If, and Else commands. I will be talking more about them next time. Please make your own VBS and post them here and I can help you out.