Thread: Global/Public
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Global/Public

The limitations of the latter is that it doesn't work.

If they are public to the whole project, accessible from any module, declare
them as public in declaratives

Public myString as String
Public Const myConst as Integer = 1

If they are private to the module, accessible only to that module, declares
them as private in declaratives

Private myString as String
Const myConst as Integer = 1

If they are private to the procedure, not accessible b y any other
procedure, in that module or any other, declare them as private in the
procedure

Sub Main()
Dim myString as String
Const myConst as Integer = 1

--
HTH

Bob Phillips

(replace somewhere in email address with googlemail if mailing direct)

"Fox via OfficeKB.com" <u18899@uwe wrote in message
news:60d655f7da51d@uwe...
If I have any global variable and/or constants to declare, and they are
limited to one module, which is the better method to declare them:

Option Explicit
Dim myString as String
Const myConst as Integer = 1

Or

Option Explicit

Sub Main()
Public myString as String
Public Const myConst as Integer = 1

What are the advantages and/or limitations of each? And while we're at

it,
what about declaring as variable as Static?

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200605/1