CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    redim instruction

    Hi,
    does anybody know if the 'REDIM' instruction
    can be applied to an array? (to change his lenght). And if it can,
    does the arra

  2. #2
    Guest

    Re: redim instruction

    use the Redim Preserve Syntax to redimension an array and keep its values as in
    dim a() as integer
    redim preserve a(10)


  3. #3
    Guest

    Re: redim instruction

    Hi,

    Yes! Redim instruction is part of the array use.

    There are static and dynamic arrays.
    Most programmers don't use static arrays because one rarely knows at compile time how many items you
    need and also because static arrays can't be resized (with Redim) during execution.

    You declare and create dynamic arrays in two distinct steps. In general, you DECLARE the array to account for
    its visibility (e.g at the beginning of a module if you want to make it visible by all the procedures in the module), using
    a DIM command with an empty pair of brackets.

    Then you create an array when you actually need it, using the <ReDim> statement.

    'Array defined in a BAS modul
    Dim Customers() as String

    Sub Main()
    'Here you create the array
    Redim Customer(1000) as String
    End Sub

    Dynamic arrays can be recreated at will.
    If you want to resize an array witghout losing its contents, use <Redim Preserve>

    Redim Preserve Customers(2000) as String

    OK?

    Jan


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured