DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: redim help !!!

  1. #1
    Join Date
    Nov 2005

    redim help !!!

    can somebody please help me about the redim statement .. i'm having trouble in it .. please any show me an example of it (code) .. then explain it on me in plain english .. please .. thnx in advance ..

  2. #2
    Join Date
    Aug 2005
    The mothership provides a pretty good explanation at

    ReDim Statement
    See Also Example Specifics

    Used at procedure level to reallocate storage space for dynamic array variables.


    ReDim [Preserve] varname(subscripts) [As type] [, varname(subscripts) [As type]] . . .

    The ReDim statement syntax has these parts:

    Part Description
    Preserve Optional. Keyword used to preserve the data in an existing array when you change the size of the last dimension.
    varname Required. Name of the variable; follows standard variable naming conventions.
    subscripts Required. Dimensions of an array variable; up to 60 multiple dimensions may be declared. The subscripts argument uses the following syntax:
    [lower To] upper [,[lower To] upper] . . .

    When not explicitly stated in lower, the lower bound of an array is controlled by the Option Base statement. The lower bound is zero if no Option Base statement is present.

    type Optional. Data type of the variable; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String (for variable-length strings), String * length (for fixed-length strings), Object, Variant, a user-defined type, or an object type. Use a separate As type clause for each variable being defined. For a Variant containing an array, type describes the type of each element of the array, but doesn't change the Variant to some other type.


    The ReDim statement is used to size or resize a dynamic array that has already been formally declared using a Private, Public, or Dim statement with empty parentheses (without dimension subscripts).

    You can use the ReDim statement repeatedly to change the number of elements and dimensions in an array. However, you can't declare an array of one data type and later use ReDim to change the array to another data type, unless the array is contained in a Variant. If the array is contained in a Variant, the type of the elements can be changed using an As type clause, unless youre using the Preserve keyword, in which case, no changes of data type are permitted.

    If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.

    ReDim X(10, 10, 10)
    . . .
    ReDim Preserve X(10, 10, 15)

    Similarly, when you use Preserve, you can change the size of the array only by changing the upper bound; changing the lower bound causes an error.

    If you make an array smaller than it was, data in the eliminated elements will be lost. If you pass an array to a procedure by reference, you can't redimension the array within the procedure.

    When variables are initialized, a numeric variable is initialized to 0, a variable-length string is initialized to a zero-length string (""), and a fixed-length string is filled with zeros. Variant variables are initialized to Empty. Each element of a user-defined type variable is initialized as if it were a separate variable. A variable that refers to an object must be assigned an existing object using the Set statement before it can be used. Until it is assigned an object, the declared object variable has the special value Nothing, which indicates that it doesn't refer to any particular instance of an object.

    Caution The ReDim statement acts as a declarative statement if the variable it declares doesn't exist at module level or procedure level. If another variable with the same name is created later, even in a wider scope, ReDim will refer to the later variable and won't necessarily cause a compilation error, even if Option Explicit is in effect. To avoid such conflicts, ReDim should not be used as a declarative statement, but simply for redimensioning arrays.

    Note To resize an array contained in a Variant, you must explicitly declare the Variant variable before attempting to resize its array.

Similar Threads

  1. Replies: 1
    Last Post: 10-25-2005, 08:59 AM
  2. They created J#, why couldn't they do VB#?
    By Thomas Eyde in forum .NET
    Replies: 290
    Last Post: 12-22-2001, 03:13 PM
  3. Turn InStr(w, x, y, z) into InStr(w, x1, y1, vbBinaryCompare) ?
    By Joe \Nuke Me Xemu\ Foster in forum VB Classic
    Replies: 8
    Last Post: 12-21-2001, 08:21 PM
  4. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 11:50 PM
  5. Win NT NetGroupGetUsers error
    By Jason Kost in forum VB Classic
    Replies: 4
    Last Post: 03-24-2000, 01:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center