Solved

Deleting or Clearing an array

Posted on 2014-09-05
8
171 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 45

Accepted Solution

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

Author Comment

by:dwe0608
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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
 
LVL 1

Author Comment

by:dwe0608
Comment Utility
...
         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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Yes, exactly, or as you found out, you can also use Erase.
0
 
LVL 45

Assisted Solution

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

Author Closing Comment

by:dwe0608
Comment Utility
Thanks greatly Martin
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now