Like most (all?) programming languages, VBScript lets you perform calculations with numerical variables (Integers and Singles) You can perform the normal arithmetic operations on numerical variables:
- Addition using +
- Subtraction using –
- Multiplication using * (shift 8)
- Division using /
We can perform these calculations on variables that are for numbers.
sumInteger = num1Integer + num2Integer
The script will take the current values for num1 and num2, and then add them together and store the result in a variable called sumInteger.
DIM num1Integer, num2Integer, differenceInteger
num1Integer = inputbox(“Enter an integer.”)
num2Integer = inputbox(“Enter a 2nd integer.”)
differenceInteger = num1Integer – num2Integer
msgbox “The difference between the two numbers is: ” & differenceInteger
After working through the above example…
Use Notepad++ or some such program and create a script that:
- Declares variables to hold two numbers and their product.
- Get the two numbers from the user, using input boxes.
- Calculate the product by multiplying the two numbers together and storing the answer in the productInteger variable.
- Display the value of the productInteger variable in a message box with a message.
Save your script file and run it to test it. Then hand in your code as a .txt file.