Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there any real difference between dim and private?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
Curiously in the help, I don't seem to see any difference between using private or dim.
Have I missed anything?
 
I meant when dimensioning a variable eg
Dim strongm as Integer
Private strongm as Integer

You can use Private or DIM like this in a form or module and it appears to work the same!

Is there something subtle that I am missing?

I didnt mean as in Private Function Ted()
 
Im prob should have said Private strongm as Double
 
As I remember it the Private keyword (re variables) was introduced in vb2 or vb3 simply to complement the new Public keyword. The latter became preferred over the previous (and still existing) Global keyword.I don't think using Dim is different from using Private except that the latter makes your code more self documenting.
 
>I meant when dimensioning a variable eg

So did I. Try using Private in a Function or Sub.
 

At module level there is no difference between Private and Dim.
"Private" seems better to use in order to keep a contrast against variables declared "Public", and may also help in understanding code easier, as HughLerwill mentions.

"Private" cannot be used to declare a variable in a proceedure, as strongm was showing.
 
Sorry, I meant "when dimensioning a variable at the top of the form" That is what I was questioning what was the difference if any. It works at the top of my forms just as it does in a module (but I agree not in a procedure).
So it is a historical thingy?
 
>It works at the top of my forms just as it does in a module
Both are modules: There are normal bas modules and there are class modules, which the latter is what you see in the form code window.

>So it is a historical thingy?

As far as I know, it was introduced for the reasons already mentioned by HughLerwill and myself.
 

>class modules, which the latter is what you see in the form code window.

Hmmm that's a new one on me!
When I look at my Add Project list I see entirely separate entries for Forms, Modules and Class Modules.
 
>So it is a historical thingy?

Well Public, Private and Friend were really introduced when VB shifted to being based on COM and allowing us to write classes. The idea was that they were closer to what C++ used.
 
>Forms, Modules and Class Modules, hmmm new...

While the vb IDE makes a distinction I think Forms can generally be regarded as being a Classes with a user/ visual interface.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top