dwe0608
asked on
Deleting or Clearing an array
Hi guys
I create an array as follows:
Now what I would like to do is empty the array and reuse it ...
How would I do that?
I create an array as follows:
Global vRoleNames()
...
' r is a valid recordset
If r.RecordCount > 0 Then
ReDim vRoleNames(r.RecordCount, 2)
i = 0
Do While Not r.EOF
' AddData r.Fields("txt"), r.Fields("descr")
vRoleNames(i, 0) = r.Fields("Role")
vRoleNames(i, 1) = r.Fields("Role_memo")
i = i + 1
r.MoveNext
Loop
End If
...
Now what I would like to do is empty the array and reuse it ...
How would I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can't just do
vRoleNames
you need instead to Redim with dimensions like you have in your existing code. In the existing code it's Redim-ed as an array with r.recordcount is the number of rows and 2 as the number of columns.
vRoleNames
you need instead to Redim with dimensions like you have in your existing code. In the existing code it's Redim-ed as an array with r.recordcount is the number of rows and 2 as the number of columns.
ASKER
...
If r.RecordCount > 0 Then
==> ReDim vRoleNames(r.RecordCount, 2) <== like this ?
i = 0
Do While Not r.EOF
...
so as per the marked code above
Yes, exactly, or as you found out, you can also use Erase.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks greatly Martin
You're welcome and I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
ASKER
redim vRoleNames
and it throws an error "syntax error"
I did a little more research and found that the proper syntax appears to be
erase vRoleNames
then redim ... as per inside the code posted ..
does that sound right - it seems to work