Handling Arrays in VBScript

Written by Amrit Hallan


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.

Thenrepparttar for loops dumpsrepparttar 107893 entire array ontorepparttar 107894 HTML page. People familiar withrepparttar 107895 for() {.} loop of JavaScript will notice thatrepparttar 107896 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 sortrepparttar 107897 array in ascending order, that is, fromrepparttar 107898 lowest torepparttar 107899 top most inrepparttar 107900 alphabetical array.

So what'srepparttar 107901 logic?

1. Comparerepparttar 107902 first name withrepparttar 107903 second name 2. Ifrepparttar 107904 second name is lower thanrepparttar 107905 first name, then swap 3. else 4. Comparerepparttar 107906 first name withrepparttar 107907 third name 5. Ifrepparttar 107908 third name is lower thanrepparttar 107909 first name, then swap 6. else 7. Comparerepparttar 107910 first name withrepparttar 107911 fourth name 8. Ifrepparttar 107912 fourth name is lower thanrepparttar 107913 first name, then swap 9. else 10. Comparerepparttar 107914 first name withrepparttar 107915 fifth name 11. Ifrepparttar 107916 fifth name is lower thanrepparttar 107917 first name, then swap

So byrepparttar 107918 time we have reachedrepparttar 107919 11th step, we haverepparttar 107920 lowest name atrepparttar 107921 first position.

The second round starts atrepparttar 107922 second index index, asrepparttar 107923 first we already know isrepparttar 107924 lowest.

1. Comparerepparttar 107925 second name withrepparttar 107926 third name 2. Ifrepparttar 107927 third name is lower thanrepparttar 107928 second name, then swap 3. else 4. Comparerepparttar 107929 second name withrepparttar 107930 fourth name

and so on

I hope you've understoodrepparttar 107931 logic now. Let's see how it looks programmatically:


For years I’ve been a stay-at-home mom, and I have only recently gone back intorepparttar work force. I’ve done pretty well for myself, but I could have really saved some time and frustration inrepparttar 107892 beginning if I’d just known a few things about how to use a computer.

I come fromrepparttar 107893 era ofrepparttar 107894 typewriter and adding machine, andrepparttar 107895 computer was really intimidating to me at first. When I first enteredrepparttar 107896 business world, I lived in constant fear of losing my document or crashing my machine. The word processor was my enemy, as was business email. The only thing I could figure out was how to open incoming messages. This was fine for trading those cute stories about angels with my friends, but it had my boss in a rage. Now, those of you who knowrepparttar 107897 difference between an attachment and a hyperlink can stop reading, but if you’re as confused as I once was, read on. I’ve got some useful tips.

First, face your fear. The computer is just a machine. It’s not going to yell at you or blow up. Don’t be afraid to press a key or click on an icon (those little picture boxes that link you to programs and things.) Quite often I would end up staring at my screen afraid to move, because I didn’t know what to do next and I was afraid ofrepparttar 107898 consequences of makingrepparttar 107899 wrong decision. I wasted so much time. Just dive in. If you end up doing something that looks funny or wrong, you can almost always find a solution.

Second, save your work. This is so important in word processing programs. Have you ever been typing along, only to hit a wrong key and have your entire document disappear? Boy, I sure have. This doesn’t have to happen. If you just remember to hit "save" (underrepparttar 107900 file menu on most all word processors) every few sentences,repparttar 107901 most you’ll ever lose is a phrase or two.

Cont'd on page 2 ==>
 
ImproveHomeLife.com © 2005
Terms of Use