Solved

Deleting or Clearing an array

Posted on 2014-09-05
8
178 Views
Last Modified: 2014-09-06
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?
0
Comment
Question by:dwe0608
  • 5
  • 3
8 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40307162
If you Redim the array again it will be cleared.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40307210
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
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40307216
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dwe0608
ID: 40307220
...
         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
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40307239
Yes, exactly, or as you found out, you can also use Erase.
0
 
LVL 47

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 40307240
This article is a good explanation of arrays.
0
 
LVL 1

Author Closing Comment

by:dwe0608
ID: 40307241
Thanks greatly Martin
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40307549
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question