Array Declaration: .Array declaration are of two types,depending upon the use of the array and the fact whether we know the size of array in advance.
Below are described these one by one.Static Declaration: In this we must know the exact size of the Array we are gonna use.Below is syntax for the array declaration
Dim Ary(10)..
Array are zero based in VBScriptig so the total no of element in the above mentioned array is 10+1=11 elements.
During declaration of the array we mention the maximum subscript we are gonna use.
data can be assigned using the indexed
Ary(0)=15 Ary(1)=50
and in same manner it can be retrieved too.
var1=Ary(1) msgbox var1 Output: 50
Arrays can be multidimensional (maximum 60 dimensions). Below is an example of 2-D array with 10 rows and 11 columns.
Dim Ary(9,10)
Dynamic Array Declaration: In this we don't need to know the exact size of array we can change the size of array as we move further.
Dim DynamicAry() Redim DynamicAry()
Now when we use dynamic array we dont mention sige subscript in Dim statement.
Instead each time while using we mentioned the increased size.
Dim DynamicAry() Redim DynamicAry(0) DynamicAry(0)=12 Redim Preserve DynamicAry(1) DynamicAry(1)=13 msgbox DynamicAry(0) msgbox DynamicAry(1) :Output 12 13Preserve is a keyword which tells the VBScript engine to use preserve the content the of array while changing the size of the array.
I will be posting more on String and Array manipulation in future posts.Keep watching.... :)
Please comment for any query or concerns.
No comments:
Post a Comment