Solved

Global variables

Posted on 1998-07-12
3
163 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 50 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

728 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