Tuesday, February 26, 2013

Write a Script to print the phone list in VB Script using Arrays.

Here we are using a static array because we are giving the lowerbound and upperbound of the array. Also we are giving the array values. The script in VB looks like this. You can copy the script and paste it in a notepad and save as a .vbs file and execute it. You have to remember that the column and Row count in VB using Arrays start by default with zero and hence for 3 columns we are giving 2 because 0 to 2 makes it 3 columns and like wise for rows.


'Initializing an array with 3 columns and 4 rows

Dim arrphonelist(2,3)

'Giving all the values of different columns for the 4 rows.
Arrphonelist(0,0) = "John"
Arrphonelist(1,0) = "Abharam"
Arrphonelist(2,0) = "9854685623"

Arrphonelist(0,1) = "Mark"
Arrphonelist(1,1) = "Robin"
Arrphonelist(2,1) = "9955662233"

Arrphonelist(0,2) = "Peter"
Arrphonelist(1,2) = "Marshal"
Arrphonelist(2,2) = "8080454525"

Arrphonelist(0,3) = "Alex"
Arrphonelist(1,3) = "Blackston"
Arrphonelist(2,3) = "9865653526"

'Initializing the upperbound of the array for checking the no of rows
'for this we have entered 2 which represents the 2nd dimension
arrubound = ubound(arrphonelist,2)

For i = 0 to arrubound
      str = str&arrphonelist(0,i)&" "
      str = str&arrphonelist(1,i)&" "
      str = str&arrphonelist(2,i)&vbnewline
Next

aaaMsgbox "The Phone List is "&vbnewline&str

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.