473,503 Members | 544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused about dynamic VB Arrays and ReDim

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
5 2170
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
39428
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
6
2733
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
4
1460
by: mom_newbie | last post by:
Hello all, I want to perform the following task: 1. Create an array 2. Fill it up (number of elements unknown in advance) 3. Iterate through it using For Each loop (cannot do this in the in...
2
2352
by: DJAudette | last post by:
Hello I am using vba in excel. I am trying to do the following seeing instr is not working I am writing my own program. Just I am having an issue with this dynamic array. here is a clip of...
6
4270
by: chad | last post by:
assuming I have 2GB memory. And 1.5GB available. dim c1(,) as byte redim c1(1000, 1024*1024) throws system.outofmemoryexception. I'm like... huh? Initially I thought a lot of space is taken...
12
1788
by: divya | last post by:
1. If The size of the array is unknown during programming time then how is such array declared?? Suppose there is an Array named arrClashname(size unknown at start), Now when the clash occurs...
9
5345
by: Anil Gupte | last post by:
I am having a problem using Multidim arrays. I want to create an array which as I understand it is dimensioned as: dim xyz (rows,columns) as String I want to populate it with rows from a...
3
1464
by: Keriana30 | last post by:
I need to base a variable array using a variable. For example, ReDim pstrDepSSN(pintRecordCount) as string The only way to do this is with the ReDim statement but it doesn't permit me to...
1
1049
by: headware | last post by:
Do you have to manually release memory allocated by creating a dynamic array using ReDim? In other words, if I have the following code: ReDim Test(1000) For i = 0 To 1000 Test(i) = "test value...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.