ReDim Statement
ReDim Statement is used to declare dynamic-array variables and allocate or reallocate storage space.
ReDim [Preserve] varname(subscripts) [, varname(subscripts)]
• Preserve - An Optional parameter used to preserve the data in
an existing array when you change the size of the last dimension.
• varname - A Required parameter, which denotes Name of the variable,
which should follow the standard variable naming conventions.
• subscripts - A Required parameter, which indicates the size of the array.
Example
In the below example, an array has been redefined and then
preserved the values when the existing size of the array is changed.
Note : Upon resizing an array smaller than it was originally,
the data in the eliminated elements will be lost.
<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
Dim a()
i=0
redim a(5)
a(0)="XYZ"
a(1)=41.25
a(2)=22
REDIM PRESERVE a(7)
For i=3 to 7
a(i)= i
Next
'to Fetch the output
For i=0 to ubound(a)
Msgbox a(i)
Next
</script>
</body>
</html>
When we save the above script as HTML and execute it
in Internet Explorer, it produces the following result.
XYZ
41.25
22
3
4
5
6
7
No comments:
Post a Comment