VBS :Tutorial 3 (Array)
Array
·
Dim variable_name(upper_limit)
·
Arrays can have multiple dimensions-VBScript supports up
to 60.
·
By default, index number starts from 0
Example1:
Dim A(3)
A(0) = 256
A(1) = 324
A(2) = 100
A(3) = 55
Example2:
Dim a(1)
a(0)=1
a(1)="gh"
msgbox a(0)
msgbox a(1)
Example3:
Dim A(1,1)
A(0)(0)=0
A(0)(1)=0
A(1)(0)=1
A(1)(1)=1
Keywords:
1.
ubound
2.
lbound
3.
Accessing multidimensional Array
4.
isArray
Example
Dim
aArray()
msgbox
isArray(aArray)
Example1
:
Dim a(3)
msgbox
ubound(a)
msgbox lbound(a)
Example2
:
Dim a(1,2)
msgbox ubound(a,2)
msgbox ubound(a,1)
Example
Dim
aArray(1,1),bArray,iSize_R,iSize_C
aArray(0,0) =4
aArray(0,1) =5
aArray(1,0) =6
aArray(1,1) =7
bArray
=isArray(aArray)
iSize_R =
(ubound(aArray,1)+1)
iSize_C =
(ubound(aArray,2)+1)
msgbox (bArray
&vbnewline &"Array upper size of row is = "&iSize_R
&vbnewline&"Array's column size is= "&iSize_C
&vbnewline&aArray(0,1))
-----------------------------------------------------------------------------------------------------------------------
Fixed and Dynamic
Dim and Redim
Example1 :Both Redim
ReDim a(3)
msgbox ubound(a)
Redim a(4)
msgbox ubound(a)
Example2 :One Dim and
other Redim
Dim a(3)
msgbox ubound(a)
Redim a(4)
msgbox ubound(a)
Example3 :Both Redim
along with Data
ReDim a(0)
a(0)="a"
msgbox ubound(a)
msgbox a(0)
Redim a(1)
msgbox ubound(a)
msgbox a(0)
---------------------------------------------------------------------------------------------------------------------
Preserve
Example :Both Redim and Preserve
ReDim a(0)
a(0)="a"
msgbox ubound(a)
msgbox a(0)
Redim preserve a(1)
msgbox ubound(a)
msgbox a(0)
Example
redim a(1)
a(1)=1
a(0)=2
msgbox a(0) &vblf
&a(1)
redim preserve a(2)
'a(1)=5
'a(0)=7
a(2)=4
msgbox a(0) &vblf
&a(1) &vblf &a(2)