Wednesday, August 1, 2012

Arthemetic Operators in VB Script

Following are the different kind of arthemetic operators used in VB Script coding (+, -, *, /, mod, ^, \). They are used in the script to acheive different results on numeric values.

Instead of hardcoding the values in the script the user can either get the input from the user executing the vb script by using inputbox method or can be driven from an excel sheet.

The input of values is again based on the requirement. It gives flexibility for the user if the values are coming from an external source.

a) Addition (+)

Hard Coded Values in the script.

dim x, y
X=1
Y=2
z=x+y
msgbox z
The output would be 3
It should be noted that vb scripting is not case sensitive so the script does not throw error if X or x is used in the script.

Input values from the user for the above script.

dim x, y
X=cint(inputbox("Enter the First Value: "))
y=cint(inputbox("Enter the Second Value to be added with the first value: "))
z=x+y
msgbox "The total of first and second value is: "&z
b) Subtraction (-)

dim x, y
X=cint(inputbox("Enter the First Value: "))
y=cint(inputbox("Enter the Second Value to be subtracted from the first value: "))
z=x-y
msgbox "The final value after subtraction is: "&z
c) Multiplication (*)

dim x, y
X=cint(inputbox("Enter the First Value: "))
y=cint(inputbox("Enter the Second Value to be multiplied with the first value: "))
z=x*y
msgbox "The final value after multiplication is: "
More on Arthemetic operators will be posted in the nex blog.

No comments:

Post a Comment