Redim

Syntax

Redim [Shared] Var1[(Size1 [, Size2] [, ...])] [, Var2[(Size1 [, Size2] [, ...])]]

Redim Var As DialogName

Redim Var As UserDialog

Remarks

Empties array variables so that the array elements can be redefined. Redim stands for "redimension" — you can specify new Size values when redefining array variables. Note that whenever you use Redim, existing array contents are lost. Redim can also redefine a dialog record for a Word dialog box or a custom dialog box. For descriptions of arguments used with Redim, see Dim.

Examples

This example illustrates how you might use Redim to recycle the storage space in an array variable when you have finished using the first set of values. This helps conserve system resources.


Dim BigArray$(100)
BigArray$(0) = "A long text string"
'Series of statements that define array elements 1 through 99
BigArray$(100) = "Another long text string"
'Series of statements that make use of the values in BigArray$()
Redim BigArray$(100)
'Series of statements that define and make use of new array elements

The following macro retrieves the author name from the Summary Info dialog box (File menu) and the user name from the User Info tab in the Options dialog box (Tools menu), and then compares the two values. If they are different, a message box is displayed.

The Dim statement stores the array of values from the Summary Info dialog box in the dialog record dlg. After the author name is retrieved, these values are no longer needed. Redim can therefore recycle the dialog record dlg to store the values from the User Info tab (Options dialog box).


Sub MAIN
Dim dlg As FileSummaryInfo
GetCurValues dlg
Author$ = dlg.Author
Redim dlg As ToolsOptionsUserInfo
GetCurValues dlg
UserName$ = dlg.Name
If Author$ <> UserName$ Then
    MsgBox "Author does not match user."
End If
End Sub

See Also

Dim, Let