Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Global variables

Posted on 1998-07-12
3
Medium Priority
?
166 Views
Last Modified: 2010-05-03
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
Comment
Question by:SueBond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
tstrob earned 100 total points
ID: 1465521
Add a module and declare the variable in this module as public.

0
 
LVL 6

Expert Comment

by:alamo
ID: 1465522
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
 
LVL 6

Expert Comment

by:alamo
ID: 1465523
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question