Siebel VB Language Reference > VB Language Reference >

ReDim Statement

This standard VB statement changes the upper and lower bounds of a dynamic array's dimensions.


ReDim [Preserve] arrayName (lower To upper) [As [New] type], ...



The name of the array to redimension


The new lower bound for the array


The new upper bound for the array


The data type for the array elements


Not applicable


ReDim reallocates memory for the dynamic array to support the specified dimensions, and can optionally re-initialize the array elements. ReDim cannot be used at the module level; it must be used inside of a procedure.

The Preserve option is used to change the last dimension in the array while maintaining its contents. If Preserve is not specified, the contents of the array are reinitialized. Numbers are set to zero (0). Strings and variants are set to null ("").

If lower is not specified, 0 is used as the default. The Option Base statement can be used to change the default.

A dynamic array is normally created by using Dim to declare an array without a specified size. The maximum number of dimensions for a dynamic array created in this fashion is 8. If you need more than 8 dimensions, you can use the ReDim statement inside of a procedure to declare an array that has not previously been declared using Dim or Global. In this case, the maximum number of dimensions allowed is 60.

The available data types for arrays are numbers, strings, variants, records, and objects. Arrays of arrays, dialog box records, and objects are not supported.

If the As clause is not used, the type of the variable can be specified by using a type character as a suffix to the name. The two different type-specification methods can be intermixed in a single ReDim statement (although not on the same variable).

The ReDim statement cannot be used to change the number of dimensions of a dynamic array when the array has been given dimensions. It can change only the upper and lower bounds of the dimensions of the array. The LBound and UBound functions can be used to query the current bounds of an array variable's dimensions.

Care should be taken to avoid redimensioning an array in a procedure that has received a reference to an element in the array in an argument; the result is unpredictable.


This example finds the net present value for a series of cash flows. The array variable that holds the cash flow amounts is initially a dynamic array that is redimensioned after the user enters the number of cash flow periods.

Sub Button_Click
   Dim aprate as Single
   Dim varray() as Double
   Dim cflowper as Integer
   Dim x as Integer
   Dim netpv as Double
   Dim msgtext as string
   cflowper = 2
   ReDim varray(cflowper)
   For x = 1 to cflowper
      varray(x) = 4583
   Next x
   msgtext = "Enter discount rate:"
   aprate = 3.25
   If aprate > 1 then
      aprate = aprate / 100
   End If
   netpv = NPV(aprate,varray())
      msgtext = "The Net Present Value is: " (netpv, "Currency")
End Sub

See Also

Dim Statement
Global Statement
Option Base Statement
Static Statement

Siebel VB Language Reference