<%
Dim arrNuts(2)
arrNuts(0) = "Nuts"
arrNuts(1) = "4"
arrNuts(2) = "asp.com
Response.Write arrNuts(0) & arrNuts(1)
& arrNuts(2)
%>
The result would be: Nuts4asp.com
Now you may be wondering, Why did he dimension
his array as 2 when there are three parts to it. Well, arrays are
ZERO based so even though there are three parts, it actually counts
the first a zero so instead of it counting 1, 2, 3, it counts 0, 1,
2.
Now let's go a little further and Split a
string into an array.
<%
Dim strNuts, arrNuts
strNuts = "Learn about arrays now"
arrNuts = Split(strNuts," ")
For i = 0 to UBound(arrNuts)
Response.Write arrNuts(i) & "<br>"
Next
%>
This would write:
Learn
about
arrays
now
Here's basically what happened.
Split() took the string and cut it up every
where it found a blank space. This gave us each individual word. For
i = 0 is starting a loop and setting i to zero which is the lowest
number in an array. Now to UBound(arrNuts) is telling the loop how
many times to loop. UBound simply means UPPER BOUND or the highest
number in the array. In this case it said start at 0 and loop to 4
(this gives us 5 remember arrays are ZERO based. The next line:
Response.Write arrNuts(i) & "<br>"
arrNuts(i) What is the i there for? remember we told this loop i =
0. Now why is the an ampersand and a break tag?
Well, the & is used to concatenate (glue together) the break tag
and the array so it will write the array and then move down a line
when it performs it' next action. The word NEXT tells it to do it
all over again with the next word in our array.
And there it is, a very basic, simply spoken
set of array examples.
To get a grasp of the split function look here.
Someday arrays will come in useful to you. If
you want to see a working example of one, take a look at Simple
Counter Using Graphics
|