Link to home
Start Free TrialLog in
Avatar of dwe0608
dwe0608Flag for Australia

asked on

Deleting or Clearing an array

Hi guys

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

...

Open in new window


Now what I would like to do is empty the array and reuse it ...

How would I do that?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwe0608

ASKER

yes, I tried that ...

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
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.
Avatar of dwe0608

ASKER

...
         If r.RecordCount > 0 Then
==>            ReDim vRoleNames(r.RecordCount, 2) <== like this ?
             i = 0
             Do While Not r.EOF
...

Open in new window


so as per the marked code above
Yes, exactly, or as you found out, you can also use Erase.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwe0608

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