Solved

Difference between Dim and Private ,Public and Global

Posted on 2002-05-07
2
879 Views
Last Modified: 2012-08-14
What is difeerence between following scope defined for any variables
1. Private and Dim
2. Public and Global

Regards
Narendra
0
Comment
Question by:ngomte
  • 2
2 Comments
 
LVL 1

Expert Comment

by:delloro
ID: 6995671
Local variables:
Declared in any event, subroutine, or function with the keywords Dim or Static. These variables only exist within the context of the procedure in which they are declared. There is no problem with having local variables in many procedures with the same name. They all will refer to different storage spaces. If there is a conflict in names between a local variable and a more global variable, the local variable always wins. Use Static only if you don't want to lose the value in a local variable between calls to the procedure. Usually you will use Dim.

Module-level variables:
Declared in a form or BASIC module's General Declarations section, with the keywords Dim or Private. Dim is the old syntax; Private is preferred. These variables are accessible from any event, subroutine, or function procedure in the module.

old: Global variables:
Declared in any Basic Module in the project using the keyword "Global". These variables can be accessed and changed by any procedure in the project. It's best to avoid these and use the new "Public" type.

new: Public variables:
These are declared in a form or BASIC module's General Declarations section. They belong to the module in which they are declared, but they can be accessed from any procedure in the project. More about these in a later lesson...
0
 
LVL 1

Accepted Solution

by:
delloro earned 50 total points
ID: 6995674
Public Variables can make up properties inside a class module.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now