Tuesday, April 27, 2010

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

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

Here we are using a Dynamic array because we do not know the lower and upper bound of the array and the user enters the column and row count for the array. Also we are asking the user to give input the field values for the array. 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.


Method 1 for writing the script


col = InputBox("Enter the number of Columns")
row = InputBox("Enter the number of Rows")
Dim arrphonelist()

ReDim arrphonelist(col,row)

For i = 0 to row
aaaFor j = 0 to col

aaaaaaArrphonelist(j,i) = InputBox("Enter the First name")
aaaaaaaaaj=j+1
aaaaaaArrphonelist(j,i) = InputBox("Enter the Last name")
aaaaaaaaaj=j+1
aaaaaaArrphonelist(j,i) = InputBox("Enter the Phone Number")
aaaNext
Next

arrubound = ubound(arrphonelist,2)

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

aaaMsgbox "The Phone List is "&vbnewline&str


Method 2 where we only ask the number of rows and keep the columns fixed to 3


row = InputBox("Enter the number of Rows")

Dim arrphonelist()
ReDim arrphonelist(2,row)

For i = 0 to row -1
aaaFor j = 0 to 2

aaaaaaArrphonelist(0,i) = InputBox("Enter the First name")
aaaaaaaaaj=j+1
aaaaaaArrphonelist(1,i) = InputBox("Enter the Last name")
aaaaaaaaaj=j+1
aaaaaaArrphonelist(2,i) = InputBox("Enter the Phone Number")
aaaNext
Next

arrubound = ubound(arrphonelist,2)

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

aaaMsgbox "The Phone List is "&vbnewline&str

No comments:

Post a Comment