Tuesday, April 27, 2010

Write a Sample VB script using Arrays

Write a VB script using Array to print different color Names.

Here we declared an Array and indexed it to 6 columns even though we gave the index as 5. we need to remember that in VB the index starts from zero. When we declared the array and assigned the values we are now assigning the array upperbound to a variable so that using that variable we can use a for loop to print all the values.


Dim arrcolors(5)
aaaarrcolors(0) = "Blue"
aaaarrcolors(1) = "Green"
aaaarrcolors(2) = "Red"
aaaarrcolors(3) = "White"
aaaarrcolors(4) = "Black"
aaaarrcolors(5) = "Yellow"

arrubound = ubound(arrcolors)
aaamsgbox arrubound
aaaaaaFor i = 0 to arrubound
aaaaaaaaamsgbox arrcolors(i)
aaaaaaNext

aaaaaaFor each element in arrcolors
aaaaaaaaamsgbox element
aaaaaaNext

No comments:

Post a Comment