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
Solved

Deleting or Clearing an array

Posted on 2014-09-05
8
177 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 46

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 46

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 46

Expert Comment

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

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 46

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
change vba from autofit to 13.5 width? 4 29
SLMGR Switches Are Not Working On KMS Host 3 109
which modules are active in VB6 project? 6 40
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 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