dkl
Full Member
Posts: 234
|
Post by dkl on Sept 22, 2021 19:33:35 GMT -5
What is the best way if clearing out the data from an array - single and two dimensional?
I'm having trouble getting rid of the data within an array$ in order to use it again with a different set of data
I usually use a For/Next loop or Redim, but it doesn't want to work for me today!!
|
|
|
Post by Brandon Parker on Sept 22, 2021 20:03:32 GMT -5
ReDim is the fastest way to "reset" an array if you no longer require any of the original information.
'Dimension the array Dim myArray$(20)
'Add data to the array For i = 0 To 20 myArray$(i) = "My data - ";i Next i
'Print out the array to see what is in it For i = 0 To 20 Print myArray$(i) Next i
'Redimension the array; no data is saved ReDim myArray$(20)
'Print out the array to prove that nothing is is currently in it For i = 0 To 20 Print myArray$(i) Next i
'Now just put more stuff into the array For i = 0 To 20 myArray$(i) = "My data - ";(i * 10) Next i
'Print out the array to prove that we changed it For i = 0 To 20 Print myArray$(i) Next I End
{:0)
Brandon Parker
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Sept 22, 2021 20:19:07 GMT -5
Thank you for that info, Brandon. Yes that's what I thought. I been doing that, but I'm still getting old data being displayed. So, I must be looking in the wrong direction. It must be arrays that weren't defined as they didn't need to be above (10) Need to use the debugger!
|
|
|
Post by Brandon Parker on Sept 22, 2021 20:26:31 GMT -5
The arrays not being dimensioned should not matter. ReDim will wipe out the array and redimension it no matter if it was dimensioned in the first place.
{:0)
Brandon Parker
|
|