 |
Welcome |
 |
| |
|
|
| |
|
|
 |
Poll |
 |
| |
|
|
| |
|
|
|
 |
Forums |
 |
| |
VB Script Intro Lesson 1
|
|
| Andrew Husking | |
Andrew Husking [ IT User ]  Joined: Fri Apr 13 2007, 06:36PM Posts: 23 | Welcome to VBScript Introduction Course week 1
Hopefully during the time of this course I can improve the VBScript skills you have, show you different ways to achieve the same task and just overall increase your knowledge. If the answer I have is different to yours, it doesn’t mean that what you have done is wrong, because there are many different ways to achieve the same goal.
There are 2 basic ways to achieve things in VBScript, using the Windows Script coding or using VBScript coding. E.g. VBScript: msgbox “Hello World” E.g. Wscript (Windows Scripting): Wscript.Echo “Hello World”
If you put both of these lines in a text document (I use notepad to write code) and save them as a .vbs file, when you double click it, you will get very similar results(the message box may look a little different)
Ok, we start with getting input from a user, and displaying the users input on the screen.
First we need a variable to store the information the user gives us, we do this by typing “Dim VariableName” so:
Dim Name
When declaring variables, you must use only letters, VBScript can't handle having numbers in the variable name Note: A lot of people use programming best practice to declare variables e.g. for a string (text) a variable would be strName, a number would be IntAge (for an integer) Next we need to take the input from the user, we do this by using the InputBox function.
Name = Inputbox(“What is your name?”)
We put name = inputbox so that the data that is typed into the inputbox is stored in the variable.
Next, we want to display the info back to the user, we can use msgbox for this.
Msgbox (“Hello “ & Name)
Notice how i used hello in “ marks and then the & symbol then the variable name, what this does is allow us to put the hello text in the message box and also have the Name variable that we got from the user.
Next we will look at doing basic maths so using similar code as before we can do the following.
Dim NumberA Dim NumberB Dim Answer
NumberA = Inputbox("Please enter the first number") NumberB = Inputbox("Please enter the second number") Answer = Int(NumberA) + Int(NumberB) Msgbox Answer
In the above code, i use 3 variables (NumberA, NumberB and Answer) i use the inputbox and msgbox like i did in previous code, but i'm now using mathematical equations. Any of the basic maths equations can be used. E.g. A + B = Addition A - B = Subtraction A * B = Multiplication A / B = Division ( A + B ) * C etc
Also, in VBscript you may want to put Int() around all variables you are doing math with, so that VBscript treats it as a number, not a string
Next week we will look at working with dates
[ Edited Sat Feb 02 2008, 04:58AM ]
---------------------------------- Andrew Husking ERH Software Developer IT Admin, Hobby Programmer Microsoft Registered Partner
---------------------------------- A lack of planning on your part does not constitute an emergency on my part.
It's kind of fun to do the impossible.
The nice part about being a pessimist is that you are constantly being either proven right or pleasantly surprised.
Windows is a 32-bit extension to a 16-bit graphical shell for an 8-bit operating system originally coded for a 4-bit microprocessor by a 2-bit company that can't stand 1 bit of competition.
| | Back to top | |
Moderators: Andrew Husking
|
|
Powered by e107 Forum System
|
|
| |
|
|
|
 |
Online |
 |
| |
Guests: 5, Members: 0 ...
most ever online: 32 (Members: 0, Guests: 32) on 28 Apr : 05:14
Members: 5 Newest member: Shadow |
|
| |
|
|
 |
Chatbox |
 |
| |
You must be logged in to post comments on this site - please either log in or if you are not registered click here to signup
|
|
| |
|
|
 |
Google Ads |
 |
| |
|
|
| |
|
|
|

Created by Andrew Husking, ERH Software. ERH Software was inspired by and designed for my beautiful Daughter Ella Rose, the one person who i live everyday of my life for, who can melt me with her smile, make me the happiest person alive with her presence and the unhappiest in her absence. I love you darling, and don't ever forget that
|