Global Versus Public in Visual Basic

Last reviewed: July 29, 1997
Article ID: Q115512
The information in this article applies to:
  • Microsoft Visual Basic Programming System, Applications Edition, version 1.0
  • Microsoft Excel for Windows, version 5.0
  • Microsoft Project for Windows, version 4.0

SUMMARY

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.

REFERENCES

For more information about the Public Statement, choose the Search button in the Visual Basic Reference and type:

    Public
Keywords          : kbprg
Version           : 1.00
Platform          : WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.