Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Difference between Dim and Private ,Public and Global

Posted on 2002-05-07
2
Medium Priority
?
1,101 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 150 total points
ID: 6995674
Public Variables can make up properties inside a class module.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Suggested Courses

824 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