ReDim a 2 dim. array 
Author Message
 ReDim a 2 dim. array

I have the following code:
in a .bas module
Global strArray() as String
in form
for i = 1 to numofobjects
    if temp(i) Like "###T" then
        numTcount = numTcount + 1
        ReDim Preserve strArray(numcount, 2) as String
    End if
Next i
It works the first time, but the second time it tells me subscript out of
range.  What am I doing wrong?
Thanks



Tue, 25 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

I have the following code:
in a .bas module
Global strArray() as String
in form
for i = 1 to numofobjects
    if temp(i) Like "###T" then
        numTcount = numTcount + 1
        ReDim Preserve strArray(numcount, 2) as String
    End if
Next i
It works the first time, but the second time it tells me subscript out of
range.  What am I doing wrong?
Thanks



Tue, 25 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

I have the following code:
in a .bas module
Global strArray() as String
in form
for i = 1 to numofobjects
    if temp(i) Like "###T" then
        numTcount = numTcount + 1
        ReDim Preserve strArray(numcount, 2) as String
    End if
Next i
It works the first time, but the second time it tells me subscript out of
range.  What am I doing wrong?
Thanks



Tue, 25 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

You can only redim preserve a one-dimensional array

Quote:

>I have the following code:
>in a .bas module
>Global strArray() as String
>in form
>for i = 1 to numofobjects
>    if temp(i) Like "###T" then
>        numTcount = numTcount + 1
>        ReDim Preserve strArray(numcount, 2) as String
>    End if
>Next i
>It works the first time, but the second time it tells me subscript out of
>range.  What am I doing wrong?
>Thanks

begin 666 Steve Marron.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..DUA<G)O;CM3=&5V90T*1DXZ


&0T%21 T*
`
end
end


Fri, 28 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

Correction: You can only Redim Preserve the LAST index of a
multi-dimensional array.

Jonas
TRION Technologies


Quote:
>You can only redim preserve a one-dimensional array


>>I have the following code:
>>in a .bas module
>>Global strArray() as String
>>in form
>>for i = 1 to numofobjects
>>    if temp(i) Like "###T" then
>>        numTcount = numTcount + 1
>>        ReDim Preserve strArray(numcount, 2) as String
>>    End if
>>Next i
>>It works the first time, but the second time it tells me subscript out of
>>range.  What am I doing wrong?
>>Thanks



Fri, 28 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

On a more useful note, from what you are doing in the code snippet it looks
like it would be better to make an array of data types, like so
type mytype
Data1 as string
Data2 as string
end type
then on the form do a
dim array1() as mytype
redim array1(1)
for i = 1 to numofobjects
if temp(i) Like "###T" then
  If ubound(array1) >1 then
   ReDim Preserve array1(ubound(array1)+1)
   array1(ubound(array1)).Data1=temp(i)
   array1(ubound(array1)).Data2=whatever
  else
   array1(ubound(array1)).Data1=temp(i)
   array1(ubound(array1)).Data2=whatever
  endif
End if
Next i
The check looks to see if you have added any records to your initialized
array, if it has it increase the array by one and adds your information if
not it puts the information in the first member of the array.  This routine
works very fast.  You could make it even fast by by replacing all the
if...thens with select...case statements and replace for for...next with a
do...loop and an internal incrementer.
Hope this is a more useful help than the other messages I saw.  I just
wrote a routine like this over the weekend to do text parsing to a log
file, the compiled executable scans, parses and cumulates numeric data, and
it does all of this to a 2.4mb csv file and populates a sorted listbox in
under 3 seconds.
If you need anything else let me know.
Bill Bomar
Systems Analyst, MSCSE



Fri, 28 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array


Quote:
>You can only redim preserve a one-dimensional array

Ah, not quite. You can only redim the last subscript.

Ralph Sabene



Fri, 28 Jul 2000 03:00:00 GMT  
 ReDim a 2 dim. array

When you use the Preserve keyword, you can resize only the last dimension.  See ReDim statement in the Help menu.


Quote:

>I have the following code:
>in a .bas module
>Global strArray() as String
>in form
>for i = 1 to numofobjects
>    if temp(i) Like "###T" then
>        numTcount = numTcount + 1
>        ReDim Preserve strArray(numcount, 2) as String
>    End if
>Next i
>It works the first time, but the second time it tells me subscript out of
>range.  What am I doing wrong?
>Thanks



Mon, 31 Jul 2000 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Dim and ReDim?

2. Dim and ReDim

3. Dim and ReDim

4. Efficient use of strings (Dim, Redim, and all that)

5. dim and redim allocate memory?

6. multi dim array / nested array

7. clarify understanding on redim statement with dynamic arrays

8. ReDim Preserve a multi column array

9. REDIM on a multi-dimensional array

10. Redim an Array in VBScript

11. redim array

12. ReDim with 2-dimensional array

 

 
Powered by phpBB® Forum Software