VBScript TutorialIntroductionVBScript Editors VBScript Syntax VBScript Variables VBScript Arrays VBScript Date VBScript If Statements VBScript Select Case VBScript While Loop VBScript For Loop VBScript Operators VBScript Functions Summary Got a MySpace Page?Get "www.yourname.com" for your MySpace page. Learn how >>. |
VBScript ArraysA VBScript array is a special type of variable that allows you to store multiple values against a single variable. For example, say you have a shopping list that you want to store and write out to the screen. You could store these in a simple variable like this:
This will work fine. But one problem with this approach is that you have to write out each variable name whenever you need to work with it. Also, you can't do things like, loop through all your variables. If these values were stored in an array, you could save yourself a lot of time. What Does an Array Look Like?Arrays can be visualized as a stack of elements. Each element has an index number (left column) and a value (right column). Note that VBScript arrays start their numbering at zero.
Creating Arrays in VBScriptVBScript arrays are created by first assigning an array object to a variable name...
So, using our prior example, we could write:
Accessing Array DataYou can access data in an array by referring to the name of the array and the element's index number. Display a Single Array ElementThis example displays the second element of the array named shoppingList (remember that VBScript array index numbers begin at zero). In this case, the value would be Bread
So, building on our previous example, you could use the following code to declare an array, assign values, then output the contents to the screen.
This results in:
Bread
Modify the Contents of an ArrayYou can modify the contents of an array by specifying a value for a given index number:
Now, the value of the second element will be:
Wholemeal Bread
Enjoy this website?
Oh, and thank you for supporting Quackit! |
FREE Hosting!With every domain name you register with ZappyHost, you get FREE (ad supported) hosting.PLUS you get:
Featured Template:
(Build your websites in minutes!) |
||||||||