Tuesday, April 27, 2010

Write a Script to print a Phone List in VB using Arrays

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
aaastr = str&arrphonelist(0,i)&" "
aaastr = str&arrphonelist(1,i)&" "
aaastr = str&arrphonelist(2,i)&vbnewline
Next

aaaMsgbox "The Phone List is "&vbnewline&str

No comments:

Post a Comment