Link to home
Start Free TrialLog in
Avatar of SueBond
SueBond

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of tstrob
tstrob

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alamo
alamo

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!
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.