Simple Dynamic Array question

Results 1 to 3 of 3

Thread: Simple Dynamic Array question

  1. #1
    Elaine Pack Guest

    Default Simple Dynamic Array question

    Using this code snippet:<BR><BR>Dim myData()<BR>Indx = -1 [to set first iteration at 0-can U sugg. a better way?]<BR>do until rs.eof<BR> indx = indx + 1<BR> myData (indx) = SomeOtherData --&#062; error on this line<BR>. . .<BR><BR>My problem is that if I put a number in the array define statement, as in "dim mydata(20)", everything works correctly. However, if I leave it as empty parens as above, I get a "subscript out of range" error on the last line "mydata(indx) = someotherdata".<BR><BR>What I&#039;m trying to do is create an array when I don&#039;t know exactly how many elements there might be. The doc on the Microsoft scripting page shows it as using empty parens for a dynamic array, but maybe I missed something.<BR><BR>I&#039;m obviously doing something wrong here--can anyone help?? Thanks!<BR><BR>elaine

  2. #2
    Dilip Guest

    Default RE: Simple Dynamic Array question

    How about...<BR><BR>Dim myData() <BR>Indx = -1 do until rs.eof <BR> indx = indx + 1 <BR> redim preserve myData(indx)<BR> myData (indx) = SomeOtherData --&#062; error on this line <BR>. . . <BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Simple Dynamic Array question

    Hi, Elaine. You could also use getrows, which will figure out the size of the array for you and is also much faster than looping through the recordset. It&#039;s a 2D array.<BR><BR>Dim myData<BR>...<BR>myData = rs.getrows &#039;got your array - field # is 1st dim, record # is 2nd dim

Posting Permissions

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