473,699 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the Difference between Global and Public, Dim and Private variables?

26 New Member
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????

Example:

What is the difference:
' In bas Module
Option Explicit

Global gblmyVar1 as Long ' Declared as Global
Public pblmyVar1 as Long ' Declared as Public

' In Form Module

Private prvRecSet as New ADODB.Recordset ' Declared as Private
Dim dimRecSet as New ADODB.Recordset ' Decalred as Dim

Please help, thanks in advance.
Jan 20 '07 #1
11 19748
willakawill
1,646 Top Contributor
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????

Example:

What is the difference:
' In bas Module
Option Explicit

Global gblmyVar1 as Long ' Declared as Global
Public pblmyVar1 as Long ' Declared as Public

' In Form Module

Private prvRecSet as New ADODB.Recordset ' Declared as Private
Dim dimRecSet as New ADODB.Recordset ' Decalred as Dim

Please help, thanks in advance.
Hi
Global is not a vb keyword.
The MSDN library says:
Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project in which they reside.

Caution The Public statement can't be used in a class module to declare a fixed-length string variable.

Use the Public statement to declare the data type of a variable. For example, the following statement declares a variable as an Integer:

Public NumberOfEmploye es As Integer
Only use Public if you want your variable to have scope in your entire project.

As for dim:
Variables declared with Dim at the module level are available to all procedures within the module. At the procedure level, variables are available only within the procedure.

Use the Dim statement at module or procedure level to declare the data type of a variable. For example, the following statement declares a variable as an Integer.

Dim NumberOfEmploye es As Integer
Jan 20 '07 #2
hariharanmca
1,977 Top Contributor
What is the Difference between Global and Public, Dim and Private variables? in Visual Basic 6.0. Because I am always using Public and Dim but using Global and Private is doing the same thing, is there any differences between these types of declaration scopes???????

Example:

What is the difference:
' In bas Module
Option Explicit

Global gblmyVar1 as Long ' Declared as Global
Public pblmyVar1 as Long ' Declared as Public

' In Form Module

Private prvRecSet as New ADODB.Recordset ' Declared as Private
Dim dimRecSet as New ADODB.Recordset ' Decalred as Dim

Please help, thanks in advance.

Global???
Public - We can access that variable by Direct or Indirectly through all parts of Project
Private - Only a Pirticular part of Access
Dim - Just like Private and Initialize at the time of calling that part
Jan 20 '07 #3
Killer42
8,435 Recognized Expert Expert
Global is not a vb keyword.
Ah, how soon we forget... :)

Global is a holdover from earlier versions, and I believe VB still accepts it for backward compatibility. I'm fairly certain it's treated the same as Public.
Jan 21 '07 #4
willakawill
1,646 Top Contributor
Ah, how soon we forget... :)

Global is a holdover from earlier versions, and I believe VB still accepts it for backward compatibility. I'm fairly certain it's treated the same as Public.
I guess you did not try this out before posting :D
Jan 21 '07 #5
Killer42
8,435 Recognized Expert Expert
I guess you did not try this out before posting :D
No, I didn't. But I've just tried it now, and it appears to support what I said. Why?
Jan 21 '07 #6
willakawill
1,646 Top Contributor
No, I didn't. But I've just tried it now, and it appears to support what I said. Why?
My copy of VB6 refuses to let me use the global word. Access rejects it too. How about that.
Jan 22 '07 #7
Killer42
8,435 Recognized Expert Expert
My copy of VB6 refuses to let me use the global word. Access rejects it too. How about that.
Hm... maybe it's some option I turned on for compatibility? Don't remember.

I assume this was in a module and not a form, right?

(I've just had a look through the options and can't see anything that looks relevant.)
Jan 22 '07 #8
sirsnorklingtayo
26 New Member
I see I see, but you mentioned guys about Option Private Module, and I think this is the key to my answer, because in VB6 you are allowed to create multiple projects in just one Project File, Example: I have a project Named MultiProject, under that project I got 3 types of project like prj001,prj002 and prj003. So, what I think is if you will try to declare a variable in BAS Module with GLOBAL statement you can Access that variable in all of your 3 projects, So what do you think guys??? is that a probable answer to my question ?
Jan 22 '07 #9
sirsnorklingtayo
26 New Member
About the Option Private Module, I just figured it out that If VB6 implement this kind of Option then I think that is the reason why there is a GLOBAL Statement, So if you will try to disable the Option Private module then Global statement is in effect and you can access your variables with GLOBAL statement in different types of your projects.

Thanks guys I appreciate all your help and Ideas, but if you think this is not the answer you can suggest another, please don't hesitate to post your answers...
Jan 22 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

27
3799
by: gabor | last post by:
hi, as far as i know in python there aren't any private (i mean not accessible from the outside of the object) methods/fields. why? in java/c++ i can make a method private, this way unaccessible for the outside world. i think it helps a lot to make for example a library more robust.
18
2096
by: Janaka | last post by:
I'm having a discussion with my colleagues here on good programming standards. One thing we haven't agreed on is the use of properties in classes vs using member variables. Now everyone knows that it is useful to use a property when it has to do some further action on the data such as private double salesAvg; public double SalesAverage { set { salesAvg = value / salesTotal; }
3
1359
by: John C Kirk | last post by:
One odd thing I've come across - if you declare a private variable in a class, it is exposed to other instances of that same class. To replicate this behaviour, create a class like this: Public Class Class1 Private mintID As Integer = 0 Public Sub New(ByVal pintID As Integer)
1
1920
by: Steve | last post by:
I generate C# webservices proxy code from WSDL file, it turns out the classes generated have public member variables and no getter/setter methods as follows, and I am able to get data when running the client. public class MyFeeResponse {
2
3987
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the same name as the parent context, but I want direct access to the parent context's variable. E.g. I would like to be able to do this... function Point()
2
2437
by: Sky | last post by:
Hello: I'm trying to make sense of snk files, when to use, under what conditions to regenerate new ones,...can someone take a look if these statemes make sense? And then the final questions at the end that they first statements bring up in my mind... a) Because two developers, unbeknownst to each other, can end up releaseing different dll's with the same name, one should sign an assembly with a unique tag. right?
6
1528
by: t f | last post by:
Hi I have a class with a bunch of private variables in, is there an easy way to make these have public properties without having to type it all in? e.g. public class Fu { private float fBar;
0
1181
by: Jon | last post by:
Hello all, I recently posted a question about a tool that would create the public member variables for a selected set of private member variables - when there's 10 - 15 privates, it can be very tedious!. I found a number of options, but all a little costly, so I developed my own. For example, if your code has the below private members:
13
1724
by: PragueExpat | last post by:
I (think) that I've come up with a pattern that I haven't seen in any publications so far and I would like some feedback. Basically, I was looking for a way to inherit private functions and I came up with this: //base private object constructor function priv(){ this.a = 1; this.b = 2;
0
8705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8896
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.