Data structures in VBA

G

Guest

Could someone point me to a good resource on how to build data structures in
VBA for Access. The ones I am interested in are hash tables (aka associative
arrays. dictionary objects). I would like to know how to create arrays of
hashes, hashes of hashes, hashes of arrays. I would also like to know how to
traverse these types of structures (a hash). Ideally, my code would be able
to detect the type of object (array, hash, etc) and appropriately traverse
it.

if (type(object) = "array") Then
code to traverse an array
elseif (type(object) = "hash" ) then
code to traverse a hash
EndIf

Thanks.
 
A

Albert D. Kallal

I doubt you going to find any example code for such types of structures.

The reason for this is that those structures are *usually* used when the
person
does not have a database engine at their disposal. Since ms-access has a
high performance database engine that can sort, and retrieve data in your
order you need, then is really is a cold day in hell when you need to write
such structures yourself.

why would you not simply store the data in a table, and let ms-access do all
of this work?

Even the use of arrays in code has very much fallen by the way side. You
laky best use collections for storing temp lists in code, but only of that
list is not coming from a table.

So, you likely not find any of this type of code examples, since we not
written, or had to write such stuff for many years now. That time wasted is
used for feeding the poor, or giving our time to needy people.

You might perhaps explain what you are trying to accomplish here...it very
possible you are using the wrong tool....

For example, if I need to store in code some values, in the old days of
programming, you might use a VERY clumsy array. However, collections are far
more dynamic.

For example, I need to pass a "list" of field names to a verification
routine in a form. So, in the old days, I would use an array, but you have
to fix, and re-dimensions arrays. A collection is better

eg:

Private Function MyVerify() As Boolean

Dim colFields As New Collection

MyVerify = False

colFields.Add "TourDate,Tour date"
colFields.Add "Description,Description"
colFields.Add "City,City"
colFields.Add "cboProvince,Province"
colFields.Add "StartDate,Start date"
colFields.Add "EndDate,end date"

MyVerify = vfields(colFields)

the above passes a field name, and the "," (comma) seperate the error
message I want to dispaly for the required field list above.

The fucntion vfields uses the collecion as:

Private Function vfields(colFields As Collection) As Boolean

Dim strErrorText As String
Dim strControl As String
Dim vFieldcheck As Integer

vfields = False

For each vField in colFields
strControl = Split(vFieldcheck, ",")(0)
strErrorText = Split(vFieldcheck, ",")(1)
If IsNull(Me(strControl)) = True Then
MsgBox strErrorText & " is required", vbExclamation, AppName
Me(strControl).SetFocus
vfields = True
Exit Function
End If
Next vFieldcheck


End Function


My whole point here is notice how I did not use a array, nor have to
"dimension" the array. Nor did I even check as to "how" many are in the
array...since I did not use one. So, I not say arrays have gone the way of
the doe doe bird..but, we just don't have to use them that much anymore.

Further, for retrieving data, that data is in a table in the first place,
so, we don't need some hash code to retrieve that value...we use a table
with a index on it.

Where is your data coming from....is it not already in a table? Why not
leave it there? The overhead of reading that data into some type of array,
and THEN looking for a data item in it don't make a whole lot of sense...

Note that collections in ms-access can have a key value (and, as far as I
know, they actually do use a hash code internally). In vb.net, you can
actually choose the type of collection you use. unfortunately...in
ms-access...you only have the one type of collection object..

So, it kind of long shot to find some code for somthing that no one uses any
more..nor has the need to....
 

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

Top