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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dim statements 4

Status
Not open for further replies.

WaterSprite

Technical User
Mar 23, 2004
69
US


Option Explicit

[Dim pf As String]
[Public pf As String]

Do I need both of these statements? My goal is to have the variable [pf] available to the entire project. I have never done that before. I just usually do Dim statements in the modules. I went to the VBA help files, but could not figure out if using the [Public pf as string] was all I needed to do.

Thank you.
 
Do I need both of these statements?
No, use either one.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, one or the other, not both.

There is some difference in the scope. Assuming the declaration appears at the beginning of a module (outside of any procedures), then:
dim will make the variable available to all procedures within the module
public will make the variable available to procedures in all modules
 
FYI, You might also see

global PF as string

This is now the same as public. You can still use global, but public is preferred. Someday global will probably go away and only public will remain.

This article on variable scope may be helpful.
 
>No, use either one.

Whilst you can indeed use either, I'd advise using Public since it is slightly more explicit

>global PF as string

>This is now the same as public

Actually, there are occassions when Global cannot be used in place of Public (basically Global can only be used in standard modules)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top