Re: Using collection to store variable values

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks, Marsh,

I was just playing around with this concept, I don't really need the key
values but was wondering whether there was a method to do so.

A while back, I read an article that advised use of custom functions to
store variables rather than declaring Global Variables. It explaained that:

1. some global variables will lose their values when some errors occur,
causing unintended problems
2. unlike functions, you cannot use global variables as parameters in
queries, unless you build the SQL dynamically and concatenate the value of
the variable.

It described how to create the function that allows you to both set and
retrieve a value stored in a static variable. I've found this extremely
useful but in one of my programs have about a dozen of these functions. I
was toying with the idea of extending that functionality to a static
collection defined within a function, so that instead of having to have
numerous functions, I'd just have this one function that gets passed a key,
and a value (to set the value) or a key (to retrieve the value). So far,
that functionality is working fine in the test program I've developed. Have
not had a chance to test reading and writing to it multiple times (for a
speed test comparison).

The problem with using an array is that you either have to keep track of
which position the variable is stored in, or have to search the array for
the value. At least with a collection, you can get the value as long as you
know the key. Hopefully, the code that supports the collection is optimized
for this search.

Dale

"Marshall Barton" <marshbarton@xxxxxxxxxx> wrote in message
news:g699d3963im77em7g2spkvfrn6gad9tv93@xxxxxxxxxx
Dale Fye wrote:

I'm attempting to use a collection to store variable values associated
with
some of my code, so I don't have to keep using DLOOKUP to get information
from some of my tables.

I have a function that I pass a key and an optional value. If the key
value
is not part of the collection, I add it and set its value. If the
optional
value is included, the function sets the value associated with the
collections key value. if no value is provided, the function returns the
value that is already associated with the key.

How can I enumerate the key values associated with this collection? I
know
I can loop through the item numbers, but how can I see what keys are
associated with a particular item number?


It seems like a stupid omission, but you can not get the key
value from a collection. I suggest that you use a two
dimensional array instead (probably faster too).

--
Marsh
MVP [MS Access]


.



Relevant Pages

  • Re: Using collection to store variable values
    ... store variables rather than declaring Global Variables. ... and a value or a key (to retrieve the value). ... that functionality is working fine in the test program I've developed. ... The problem with using an array is that you either have to keep track of ...
    (microsoft.public.access.formscoding)
  • Re: Getting a (non-radio) buttons index number from array
    ... index in the Comment array of the button that was fired. ... you don't need js if you print out the full DOM ... There needs to be some unique way to identify the row in the database. ... Then it's easy to retrieve the ...
    (comp.lang.php)
  • Re: RegEx: finding a string that does not contain /<(w ...(-...)?|c ...)>/
    ... I have an array @a with character strings: ... I want to retrieve the sequence of ... would ideally work without lookaround (but if lookaround is absolutely ...
    (perl.beginners)
  • Re: RAM shared by graphics chip - something to worry about?
    ... The test program below spends its time reading from a large ... The array is set to 32MB, ... Disabling it ... difference is the 'CPU clock cycles' in percent? ...
    (borland.public.delphi.non-technical)
  • Re: Globals vs passing in by reference
    ... >hold this array. ... Then they increment the global int variable. ... >function or just access the global variables? ... probably) and the counter has a cost in ...
    (comp.lang.c)