By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

Confused about dynamic VB Arrays and ReDim

P: n/a
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.

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"Zenobia" <8.**********@spamgourmet.com>

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.

Nov 21 '05 #2

P: n/a
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.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight

"Zenobia" <8.**********@spamgourmet.com> wrote in message
news:ho********************************@4ax.com...
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.

Nov 21 '05 #3

P: n/a
guy
You may find a HashTable a better bet

hth

guy

"Zenobia" wrote:
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.

Nov 21 '05 #4

P: n/a
On Thu, 30 Sep 2004 13:05:37 +0200, "Cor Ligthert"
<no************@planet.nl> wrote:
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.
Otherwise the hasttable or the sortedlist is in my opinion the way to go.

I hope this helps anyhow?

Cor

"Zenobia" <8.**********@spamgourmet.com>

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.


Nov 21 '05 #5

P: n/a
Zenobia,

Than I would look as I wrote before to the hasttable, which has a key and a
value field, probably that makes it very easy.

http://msdn.microsoft.com/library/de...ClassTopic.asp

The real Array you would only use when it is very static. The redim do I see
as a comptabible function for VB6.

I hope this helps?

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.