Static Variable

I have a variable declared publicly in a module as: "PUBLIC FlagToStop as boolean" because it used thoughout my project in almost every form.

However, when I set this as "FlagToStop=True" in one form, the value of the variable doesn't carry over to other forms. I know there must be a way to do this. Maybe something with the "Static" keyword, but I tried that in the VB example, but it didn't seem to make a difference.. Any ideas?

LVL 2
cantrellAsked:
Who is Participating?
 
vettrangerConnect With a Mentor Commented:
define this variable in a module as

Global FlagToStop as boolean

It will then be available in every form with no further effort.

As mark2150 says, make sure you don't have it defined anywhere else, as the closest level definition will take precedence.
0
 
mark2150Commented:
If you have a local declaration of the SAME NAME it will override the global. Betcha you've got a duplicate of the definition. Probably this is the original form that the var was copied from.

M
0
 
cantrellAuthor Commented:
mark2150 - nope. Declared only once as public in only one module.

vettranger - the "GLOBAL" didn't make any difference than the 'PUBLIC' did. And, for some reason, "GLOBAL" isn't even listed in the vb5 help... Go figure. However, for your effort I'll give you the points.

It was a problem with me re-setting the flag in a place I shouldn't have.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
cantrellAuthor Commented:
mark2150 - nope. Declared only once as public in only one module.

vettranger - the "GLOBAL" didn't make any difference than the 'PUBLIC' did. And, for some reason, "GLOBAL" isn't even listed in the vb5 help... Go figure. However, for your effort I'll give you the points.

It was a problem with me re-setting the flag in a place I shouldn't have.

0
 
cantrellAuthor Commented:
sorry vettranger, post something - anything and i'll give you the points. I clicked the wrong button and can't give you the points until you respond again.
0
 
mark2150Commented:
Set a breakpoint on the variable's value being changed.

Research the entire project to find *ALL* references to that var name. Sure as god made little green apples there's another declaration somewhere.

M
0
 
mark2150Commented:
Sure you can. use the "Grade Comment as Answer" feature...

M
0
 
cantrellAuthor Commented:
sorry vettranger, post something - anything and i'll give you the points. I clicked the wrong button and can't give you the points until you respond again.
0
 
mark2150Commented:
See how nice that worked! :-) Is way cool feature!

M
0
 
cantrellAuthor Commented:
Thanks mark2150 - you've been most helpful in all of my questions.
0
 
vettrangerCommented:
Its obviously common for something like that to happen also! LOL

In any case, both Mark2150's comment and mine should serve you in the future. However, it is advisable to use both public and global variables judiciously, just for this reason.
0
 
cantrellAuthor Commented:
Thanks mark2150 - you've been most helpful in all of my questions.
0
 
mark2150Commented:
Vett,

I haven't noticed *ANY* difference between GLOBAL's and PUBLIC's. I've got legacy programs that were coded in VB4 that used GLOBAL's exclusively. My code always uses PUBLIC's. Have some that are mixed. Never noticed *ANY* differences between the two. Have you?

M
0
All Courses

From novice to tech pro — start learning today.