An array is a collection of logically related data items, where each item can either be accessed in a sequential order, or through supplying its index position.Consider this:
Here we declare an index of dimension 5, which later on, comes to store six names, as, an index in an array starts at 0.
Then
for loops dumps
entire array onto
HTML page. People familiar with
for() {.} loop of JavaScript will notice that
for.next loop of VBScript is less cryptic.
Since now we have learnt how to create a VBScript array, let us try to sort this array. We'll sort
array in ascending order, that is, from
lowest to
top most in
alphabetical array.
So what's
logic?
1. Compare
first name with
second name 2. If
second name is lower than
first name, then swap 3. else 4. Compare
first name with
third name 5. If
third name is lower than
first name, then swap 6. else 7. Compare
first name with
fourth name 8. If
fourth name is lower than
first name, then swap 9. else 10. Compare
first name with
fifth name 11. If
fifth name is lower than
first name, then swap
So by
time we have reached
11th step, we have
lowest name at
first position.
The second round starts at
second index index, as
first we already know is
lowest.
1. Compare
second name with
third name 2. If
third name is lower than
second name, then swap 3. else 4. Compare
second name with
fourth name
and so on
I hope you've understood
logic now. Let's see how it looks programmatically: