ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Where to declare module-level variables? (https://www.excelbanter.com/excel-programming/395969-where-declare-module-level-variables.html)

Ed from AZ

Where to declare module-level variables?
 
At the top of my module, I have
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

I want to Dim some variables that will be used by several subs in this
module. Do I put them above the Private for the Sleep, or between
this and my first Sub?

Ed


Bob Phillips

Where to declare module-level variables?
 
Doesn't really matter. I tend to put APIs first, then private, then public
variables.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Ed from AZ" wrote in message
ups.com...
At the top of my module, I have
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

I want to Dim some variables that will be used by several subs in this
module. Do I put them above the Private for the Sleep, or between
this and my first Sub?

Ed




JE McGimpsey

Where to declare module-level variables?
 
It's a matter of taste.

Personally, I use very few module-level variables, preferring to pass
variables as arguments, but my preference would be to declare the
variables first.

In article . com,
Ed from AZ wrote:

At the top of my module, I have
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

I want to Dim some variables that will be used by several subs in this
module. Do I put them above the Private for the Sleep, or between
this and my first Sub?

Ed


Ed from AZ

Where to declare module-level variables?
 
Thanks to you both. I appreciate the boost.

Ed


(PeteCresswell)

Where to declare module-level variables?
 
Per Ed from AZ:
At the top of my module, I have
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

I want to Dim some variables that will be used by several subs in this
module. Do I put them above the Private for the Sleep, or between
this and my first Sub?


My experience is that it Excel doesn't care.

I, however, prefer to have the Lib declarations as the last lines
in my module-level declarations.

No particular reason.... just started off that way. I'd guess,
the value is in consistency - whichever way you do it.
--
PeteCresswell

Dave Peterson

Where to declare module-level variables?
 
I'd use multiple modules.

One for the APIs and one for the public variables.



Ed from AZ wrote:

At the top of my module, I have
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

I want to Dim some variables that will be used by several subs in this
module. Do I put them above the Private for the Sleep, or between
this and my first Sub?

Ed


--

Dave Peterson


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com