Bookshelf Home | Contents | Index | PDF |
Siebel VB Language Reference > VB Language Reference > ReDim StatementThis standard VB statement changes the upper and lower bounds of a dynamic array's dimensions. SyntaxReDim [Preserve] arrayName (lower To upper) [As [New] type], ... ReturnsUsageReDim 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 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. ExampleThis 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 See AlsoDim Statement |
Siebel VB Language Reference |