Re: Global variables disappear



When testing your code, you often reset (Run | Reset, from code window), or
perform an operation that causes that effect. That destroys your public
variables.

While that is less likely in a production environment, it is an issue, and
it certainly makes it difficult to debug. When I first started in Access, I
created an extra public boolean variable, set it to True, tested it before
using any variable, and if not set, called the Init() function again.
Realistically, that's more trouble than it's worth, so now I don't use any
global variables at all. The only exception is where the built-in procedures
don't allow me to pass what I need, and so the lifetime that I need to rely
on is almost instantaneous.

You can use a hidden control on a form to hold a value that survives a
reset. For an extended lifetime (e.g. something that survives to the next
time you open the database again), you can write the value to a table. And
for your own functions, you can always pass the argument to the lower level
procedure.

HTH.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Teewan" <Teewan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:375454A6-CDB5-403E-A49C-EDFC14651311@xxxxxxxxxxxxxxxx
> Hi guys
>
> I have a training database, which I am still making alterations to and am
> disturbed that sometimes while working on forms etc my Global variables
> are
> suddenly all zero length strings.
>
> On opening the database the system startup opens the Switchboard form.
> The OnOpen event of the Switchboard form calls a number of functions
> located
> in the SysConfiguration module which sets the Global variables to their
> appropriate values. Every now and then those values suddenly revert to
> zero
> lenght strings for no apparent reason.
>
> It has been suggested to me that they are attached to the Swithchboard
> form
> and I would loose them when I close the Switchboard. If this is the case
> how
> and where should I be setting them from. Incidentally, I can't seem to
> make
> them zero by closing the Switchboard.
>
> I wondered if it is just a glitch occurring because I'm stopping and
> starting bits of code etc. It doesn't seem to have happened (as yet) when
> the database is being used by the average user working in there, only in
> my
> testing versions. It is making me very nervous though as I use a Global
> prefix for many of my Primary keys.
>
> Thanks in advance
> Teewan


.



Relevant Pages

  • Re: RESETTING an application
    ... and Database, but I have many global variables. ... How can I reset everything without shtching the application off (like a ...
    (microsoft.public.vb.general.discussion)
  • Re: Global variables disappear
    ... I have a training database, which I am still making alterations to and am disturbed that sometimes while working on forms etc my Global variables are suddenly all zero length strings. ... The OnOpen event of the Switchboard form calls a number of functions located in the SysConfiguration module which sets the Global variables to their appropriate values. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Global Variables - Untrapped Errors
    ... The answer could depend on what you mean by an untrapped error. ... Choosing End resets the variables, but choosing Debug lets you work with the variables until you Reset or do something that triggers a reset. ... Even something with tens of thousands of lines of VBA code would have perhaps 2 or 3 public variables reserved for very specific circumstances, and the lifetime I rely on them for would typically be a millisecond or a few seconds at most. ... seems like it is resetting all global variables when this occurs. ...
    (comp.databases.ms-access)
  • Re: global variables problems
    ... when I open a form the global variables get reset ... I agree with Doug that global variables can be problematic, ... Could it be that you defined these variables *both* in the standard ... unrelated sets of variables, so the local ones in the form wouldn't have ...
    (microsoft.public.access.modulesdaovba)
  • Re: Macro security
    ... reset the main menu bar. ... > I have successfully opened an ACCESS 2002 database in ACCESS 2003. ... I wanted to check the macro security setting so I went ... the question is must one have at least one macro for this ...
    (microsoft.public.access.security)

Quantcast