Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Scope. 1

Status
Not open for further replies.

Ed2020

Programmer
Nov 12, 2001
1,899
GB
Anybody any idea what the difference between a Global variable and a Public variable is? As I understand it:

Dim - available only within the current procedure
Private - available to all procedures in the current module
Public - available to all procedures in all modules
Global - available to all procedures in all modules.

So what's the difference between Public and Global??

Ed Metcalfe.
 
Ed,

This is from the MSDN Library July 2000 CD:

In Microsoft Visual Basic version 3.0, you can use the Global statement in the Declarations section of a module to declare a global variable. Global variables are available to all procedures in all forms and modules.

In Microsoft Visual Basic Programming System, Applications Edition, you can use the Public statement to declare a public variable, which makes the variable available to all procedures in the workbook or project.

The Public statement in Visual Basic, Applications Edition, performs the same action as the Global statement in Visual Basic version 3.0. The name Public is more intuitive when thought of in context with its counterpart, Private. When you use the Private statement to declare a variable as private, the variable is available only to the module in which it is declared.

The Global statement is supported for compatibility in Visual Basic, Applications Edition; however, Public is preferred.

Steve
 
Steve,

You're a star. Please have a purple one!

Ed Metcalfe.
ed_metcalfe@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top