Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deleting or Clearing an array

Posted on 2014-09-05
8
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 49

Expert Comment

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

Assisted Solution

by:Martin Liss
Martin Liss earned 2000 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 49

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

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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 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