473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Declaring A Variable

In the Declarations section of a form's code module, what is the difference
between the following:
Dim Flag As Boolean

Public Flag As Boolean

Private Flag As Boolean

Thanks!

Lucy
Nov 13 '05 #1
4 6273
"Lucy" <lg*****@earthlink.net> wrote in message
news:oN*****************@newsread2.news.atl.earthl ink.net...
In the Declarations section of a form's code module, what is the difference between the following: Dim Flag As Boolean
Private Flag As Boolean Either of these two declarations creates a static instance of the Boolean
variable "Flag" which is visible only to the form and not to the rest of the
application.
Public Flag As Boolean

This declaration creates a static instance of the Boolean variable "Flag"
which is visible to the entire application. For example, if you have a form
named "Form1" with the declaration statement "Public Flag As Boolean", the
"Flag" variable can be enumerated thus:
?Forms("Form1").Flag

NOTE: The form must be open for this variable to be available.

Hope this helps.
Nov 13 '05 #2
Thanks for the quick response!

Ok, I see the difference between Public and the other two. What is the
difference between Dim Flag and Private Flag? Is there a time when to use
one and not the other?

Lucy
"ByteMyzer" <sb*@nospam.news.chi.sbcglobal.net> wrote in message
news:Jv*****************@newssvr33.news.prodigy.co m...
"Lucy" <lg*****@earthlink.net> wrote in message
news:oN*****************@newsread2.news.atl.earthl ink.net...
In the Declarations section of a form's code module, what is the difference
between the following:

Dim Flag As Boolean
Private Flag As Boolean

Either of these two declarations creates a static instance of the Boolean
variable "Flag" which is visible only to the form and not to the rest of

the application.
Public Flag As Boolean This declaration creates a static instance of the Boolean variable "Flag"
which is visible to the entire application. For example, if you have a

form named "Form1" with the declaration statement "Public Flag As Boolean", the
"Flag" variable can be enumerated thus:
?Forms("Form1").Flag

NOTE: The form must be open for this variable to be available.

Hope this helps.

Nov 13 '05 #3
"Lucy" <lg*****@earthlink.net> wrote in message
news:rY*****************@newsread2.news.atl.earthl ink.net...
Thanks for the quick response!

Ok, I see the difference between Public and the other two. What is the
difference between Dim Flag and Private Flag? Is there a time when to use
one and not the other?

Lucy


As far as the declarations section of a code module are concerned, there is
significantly no difference between the Dim statement and the Private
statement. In the declarations section they serve the same purpose exactly
the same way.

However, the Private statement may only be used in the declarations section
of a module, whereas the Dim statement may be used to dynamically allocate a
variable within a procedure, in which case, the variable is only visible to
that procedure, and to no other part of the Module.
Nov 13 '05 #4
Lucy wrote:
Thanks for the quick response!

Ok, I see the difference between Public and the other two. What is the
difference between Dim Flag and Private Flag? Is there a time when to use
one and not the other?


(for short answer, skip to last para)

Back in the "good old days" Dim was used to "dimension" an array, it
still is but back then it was the only thing it was used for on BASIC,
other intrinsic variables were not declared at all.

With the advent of QuickBASIC (in the MS stable at least) we started
seeing the of "Dim" to declare variables, since "Dim" is short for
"Dimension" and intrinsic variables don't have dimensions (arrays do)
this was a pretty silly thing to use, but use it they did.

A lack of planning and/or slap happy ad-hoc development lead us down the
road of having global or shared variables in BASIC by using "Dim Shared"
in the module level to share a variable with all subs and functions,
"Shared" as a declaration in a sub/function to share it with the module
level code (entry point was at module level, no sub main back then) and
"common" to share across multiple modules although that declaration had
to exist in all modules that would see that variable. To have it in all
modules the use of an include file was quite slick.

The use of "Shared" seemed to disappear about the time of VB, probably
because of the way VB now used Sub Main or a form event as the entry
point to the program rather than the old fasioned way of module level
code and the use of "Dim" at the module level replaced "Dim Shared" and
"Global" replaced and enhanced "Common" as only one declaration was
required. (b4, "Dim" at the module level would make the variable
available to module level code only, not the subs and functions)

Later versions of VB started using "Private" and "Public" to distinguish
between module wide and global variables, this makes the module wide
declaration more explicit than "Dim", which apart from it's original use
to dimension an array, is there for backward compatability for intrinsic
variables.

--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
29
by: Friday | last post by:
Sorry if this is the wrong group. I tried to find the one I thought would be most relevant. I'm an old PHP guy, who knows little about asp and NOTHING about asp.net, but need to learn at least...
2
by: ross.oneill | last post by:
Hi, I am having trouble with a simple task of declaring a variable. Is this possible? Here is what I want to do. DECLARE start_date date; DECLARE end_date date; SET start_date =...
6
by: Steve Jorgensen | last post by:
Many of the regulars here have explained that declaring variables using As New .... is a bad idea, and some have given some good explanations, but I wanted add one more demonstration to the mix. ...
1
by: Maarten Terlingen | last post by:
Sample: ClassA: ClassB ClassB: ClassC ClassA x = new Class C I want to know the declaring type of C. x.GetType() returns C x.GetType().BaseType returns B x.GetType().BaseType.BaseType...
5
by: Brett | last post by:
In a class, I have several Private subs. I declare an instance of the class such as: Dim MySelf as new Class1 within a private sub. The motive is to provide access to other subs within the...
6
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer 2005 Express. I want to declare a varible, using Visual Basic as the language and can't get anywhere. For example Public Test1 as String I'll get en...
8
by: rendle | last post by:
I have a MSIL/performance question: Is there any difference between declaring a variable once and assigning to it multiple times, and declaring and assigning multiple times? For example: //...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
6
by: =?Utf-8?B?QUw=?= | last post by:
Hi I usually stick to the convention of not declaring variables in my bodies of "loops" (including foreach) ie int x; for (int i = 0; i < 10; i++) {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.