CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2001
    Posts
    3

    array - help!!!!!!!!

    I am using ASP and trying to add a recordset to an array - arytree1dim(0) = rst.fields("hello"). The problem is that I do not no how many records there will be until after the query is run. Therefore, I cannot declare the array like "Dim aryTree1Dim(4)" as it may have any number of records. Is there a way to use an array like this without declaring its length.

    THANKS.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: array - help!!!!!!!!

    You can ReDim an array, or in english, resize it.

    Dim arr() as string

    Redim arr(20)
    ' OR
    Redim Preserve(25)



    Of course, you could easely replace the 20 or 25 by the number of records in your recordset, by replacing it by rst.recordcount (or something like that). If you use the preserver keyword, the content of the array will be preserved, if not, the array is cleared.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Oct 2001
    Posts
    3

    Re: array - help!!!!!!!!

    when I use the recordcount as the size of the array I get the following error:

    Expected integer constant
    Dim aryTree1Dim(rsrec.recordcount)

    And I use Redim I get the following error:

    This array is fixed or temporarily locked



  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: array - help!!!!!!!!

    When declaring the array, make sure not to give a size, only assign a size when using ReDim.

    ' no size here
    Dim SomeArray() as string
    ' Size goes here
    Redim SomeArray(rst.recordcount)




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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