Confused about dynamic VB Arrays and ReDim

  • Thread starter Thread starter Zenobia
  • Start date Start date
Z

Zenobia

Hello,

I want to keep a list references to database records being
accessed.

I will do this by storing the record keys in a list. The list
must not contain duplicate keys. So I check the Contains
property before adding.

Question. Can I use an Array for this or should I use an
ArrayList? If I use an array I will declare it unsized. I can't
understand how I can add items to an array with the .Add()
method when my array is declared as static with a Dim statement.
What about ReDim? I thought that I needed to use ReDim to
change the array size each time I add an item.

PS: I have no idea how long the array will be.
 
Zenobia,

I do not understand your solution.

You want to list which database records are accessed.

You want to use for that an array or whatever which should holds duplicate
keys, which is no problem with an arraylist, it holds objects, so that can
be everything.

However how do you know to which arrayitem the accessed record belongs when
there are duplicates

I am curious how you are doing that?

Otherwise the hasttable or the sortedlist is in my opinion the way to go.

I hope this helps anyhow?

Cor
 
Hi,

If you ReDim an array you need to specify Preserve to keep what is in the
array and then specify the new number of elements:

Dim MyArray() As Integer

ReDim MyArray(0)
MyArray(0) = 1
......

ReDim Preserve MyArray(1)
MyArray(1) = 2

Now MyArray(0) still equals 1 and MyArray(1) equals 2. Good luck! Ken.
 
Zenobia,

I do not understand your solution.

You want to list which database records are accessed.

You want to use for that an array or whatever which should holds duplicate
keys, which is no problem with an arraylist, it holds objects, so that can
be everything.

However how do you know to which arrayitem the accessed record belongs when
there are duplicates

I am curious how you are doing that?

Sorry. My mistake for causing confusion. There are no duplicate
records. I meant duplicate access. If a record is recorded as
being accessed more than once there will be only on list entry
to record that. (i.e. no duplicates in the list)

I'm using an ArrayList at the moment as I just read an article
that put me off arrays big time. Way too tedious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top