Global variables

I am just learning VB4 and i have a simple problem.
I want to decare a variable that i can access from several different forms. I have tried using 'public *** as integer' but this does not seem to work as the variable is not available in other forms.
SueBondAsked:
Who is Participating?
 
tstrobConnect With a Mentor Commented:
Add a module and declare the variable in this module as public.

0
 
alamoCommented:
There's another way to do it, one that makes more sense in some cases.

When the variable is declared Public in a form, you can access it from anywhere by qualifying the variable name with the name of the form. For example:

Declaration in general section of Form1:
 Dim str as String

Reference from Form2:
 Debug.Print Form1.str

Hope this helps!
0
 
alamoCommented:
oops excuse my typo-
 Dim str as String
should have been
 Public str as String

since the whole point was to make the variable public! Sorry.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.