Solved

Public vs Global

Posted on 2003-10-23
4
323 Views
Last Modified: 2010-08-05
I have some code which came from an old VB3 project.

The some constants and variables are declared as Global. In some VB6 code I have they are declared as Public.

Is there actually a functional difference between the two methods of declaration.
0
Comment
Question by:colindow
[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
  • 2
4 Comments
 
LVL 4

Expert Comment

by:JohnChapin
ID: 9606354
Global variables are those variable declared using PUBLIC in bas module, and therefoe canbe seen throughout the project.
They survive for the life of the application and are visible from all of the application.
Microsoft supports the term in VB6 but does not encourage its use.

Public variables declared in FORM or Class modules are only valid while that form or class is instantiated (existing).

Hope this helps, John
0
 

Author Comment

by:colindow
ID: 9606387
so replacing Global Const With Public Const in all bas files will not change anything but will mean that the syntax is more consistent?
0
 
LVL 4

Accepted Solution

by:
JohnChapin earned 50 total points
ID: 9606402
That's right.
However, according to the book, you should not have to replace them.
There should be no compile error on those statements.
Are you having a problem compiling with something?
John
0
 

Author Comment

by:colindow
ID: 9606489
No, I assumed that they were the same but just before I went for the Replace button I thought I might just check.....

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

749 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