All Statements
Array Function
Option Explicit Statement
Private Statement
Public Statement
ReDim Statement
Set Statement
STATEMENT: Dim
Implemented in version 1.0
Dim
The
Dim
statement allows you to explicitly declare one or more new variables and to allocate storage (memory) space.
While you do not have to use
Dim
to create new variables in VBScript, the wise programmer prefers to use
Dim
. In fact, many programmer purposely include the
Option Explicit
statement in all of their VBScript programs which mandates that all variables be explicitly declared.
Code:
<% Dim myvariable %>
<% Dim OneVar, TwoVar, ThreeVar, FourVar, MoreVar, EvenMoreVar %>
Dim
can also be used to create static (fixed) and dynamic arrays.
A static array has the number of elements declared by the
Dim
statement. However, you must remember that the elements in an array are numbered starting at zero. Consider the following
Dim
declaration. It creates a static array containing six elements that are numbered 0, 1, 2, 3, 4 and 5.
Code:
<% Dim SixElementArray(5) %>
A dynamic array is declared using empty parentheses. At a later point in your program, you can use the
ReDim
statement to declare the number of dimensions and elements. In fact, you can redeclare a dynamic array as many times as you desire.
Code:
<%
Dim SomeArray()
...
ReDim SomeArray(22)
...
ReDim SomeArray(500)
%>
Arrays can also have up to sixty dimensions. For example, the following code creates a three dimensional array. The first dimension has 23 elements, the second dimension has 15 elements and the third dimension has 201 elements. Therefore, there are a total of 23x15x201 = 69345 elements in this array.
The number of dimensions that you can create is limited by the available memory. If you exceed the available memory while declaring an array, you will get an error message.
Code:
<% Dim ThreeDimensionArray(22, 14, 200) %>
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information