Search
Sponsors

arrays in VBScript


arrays in VBScript

Arrays

What if you want to declare numerous values to a single variable . This is when we use an array . To declare an array we use the same syntax as a normal variable declaration but add ( ) on the end .

Here is an example

dim grades(4)

How many elements do you think we have created here is it 4 , in fact we have created 5 because arrays are zero based . This is an example of a fixed size array.

We can assign data to the array like this

grades(0) = 50
grades(1) = 80
grades(2) = 94
grades(3) = 12
grades(4) = 25

You can retrieve the data like this

myGrade = grades(0)

which would store the value 50 in myGrade

You can have more than one dimension in an array , for example here is a 2 dimensional array

Dim tictactoe(2,2)

this would create an array with 3 columns and 3 rows.

The total amount of dimensions you can have is 60

Related posts:

  1. More on Multi-Dimensional Arrays More on Multi-Dimensional Arrays In the previous chapter we noted...
  2. Pointers to Arrays Pointers to Arrays Pointers, of course, can be “pointed at”...
  3. Some more on Strings, and Arrays of Strings Some more on Strings, and Arrays of Strings Well, let’s...
  4. variables in VBScript variables in VBScript Variables Before you use a variable in...
  5. Pointers and Dynamic Allocation of Memory Pointers and Dynamic Allocation of Memory There are times when...

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: ,

Leave a Reply

Translate