Arrays are two types – Static Array & Dynamic Array
Array is a collection of data with different types of data type.
1
|
Dim ArrayName(size)
|
Where, “ArrayName” is the unique name for the array and “size” is a numeric value that indicates the number of elements in the array dimension within the array.
1
|
Dim arrayvalue(3)
|
It stores 4 values. The array always starts from 0.
1
2
3
4
|
arrayvalue (0) = 1
arrayvalue (1) = 2
arrayvalue (2) = 3
arrayvalue (3) = 4
|
There are two types of arrays: 1. Static Array, 2. Dynamic Array.
It has a specific number of elements. Once assigned, size of a static array can’t be modified at runtime.
Size of a dynamic array can be modified at runtime.
1
2
3
|
Dim arrayvalue(3)
Msgbox lbound(arrayvalue)
Msgbox ubound(arrayvalue)
|
1
2
|
Dim arrayvalue(3)
Msgbox “The array size is ”& Ubound(arrayvalue) + 1
|
1
|
array(arglist)
|
1
2
3
4
5
6
7
|
Dim arrayvalue
Arrayvalue = array(91,92,93,94)
Msgbox Ubound(arrayvalue)
Msgbox Arrayvalue(0)
Msgbox Arrayvalue(1)
Msgbox Arrayvalue(2)
Msgbox Arrayvalue(3)
|
It recreates the array and erases all the old data
Preserve should be used along with redim. It will retain the old data.
1
2
3
4
5
|
Dim arrayvalue(1)
arrayvalue(0)=10
arrayvalue(1)=20
msgbox arrayvalue(0)
msgbox arrayvalue(1)
|
1
2
3
4
5
6
7
8
9
|
Dim arrayvalue(1,1)
arrayvalue(0,0)=10
arrayvalue(0,1)=20
arrayvalue(1,0)=30
arrayvalue(1,1)=40
msgbox arrayvalue(0,0)
msgbox arrayvalue(0,1)
msgbox arrayvalue(1,0)
msgbox arrayvalue(1,1)
|
1
2
3
4
5
6
7
8
9
10
11
|
dim stm()
redim stm(1)
stm(0)=1
stm(1)=2
msgbox stm(0)
msgbox stm(1)
redim stm(2) ‘REDIM WITHOUT PRESERVE
stm(2)=3
msgbox stm(0)
msgbox stm(1)
msgbox stm(2)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
dim stm()
redim stm(2)
stm(0)=11
stm(1)=22
stm(2)=33
msgbox stm(0)
msgbox stm(1)
msgbox stm(2)
redim preserve stm(3) ‘REDIM WITH PRESERVE
stm(3)=44
msgbox stm(0)
msgbox stm(1)
msgbox stm(2)
msgbox stm(3)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
dim Stm()
redim Stm(1,1)
stm(0,0)=10
stm(0,1)=20
stm(1,0)=30
stm(1,1)=40
msgbox stm(0,0)
msgbox stm(0,1)
msgbox stm(1,0)
msgbox stm(1,1)
redim preserve stm(1,2)
stm(0,2)=50
stm(1,2)=60
msgbox stm(0,0)
msgbox stm(0,1)
msgbox stm(1,0)
msgbox stm(1,1)
msgbox stm(0,2)
msgbox stm(1,2)
|
VBScript Series:
VBScript for Automation (QTP/UFT) Testing – Part 1
VBScript for Automation (QTP/UFT) Testing – Part 2
VBScript for Automation (QTP/UFT) Testing – Part 3
VBScript for Automation (QTP/UFT) Testing – Part 4
VBScript for Automation (QTP/UFT) Testing – Part 5