• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

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.
0
SueBond
Asked:
SueBond
  • 2
1 Solution
 
tstrobCommented:
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now