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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Dim str as String
should have been
Public str as String
since the whole point was to make the variable public! Sorry.
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!