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

What's your opinion about Dim Statement location?

Status
Not open for further replies.

Dor100

Technical User
Apr 9, 2001
279
US
I'd be interested in hearing people's views on something. Does everyone feel that your Dim statements should generally appear at the beginning of your functions and subs, or do some feel it's ok and even beneficial to place them anywhere you like, especially if there's no trouble keeping track? Thanks.
 
Depends on the scope. If they are needed throughout the module, then at the top of the module. Otherwise, at the top of the sub is OK.

Have fun! :eek:)

Alex Middleton
 
Most things I've read on this subject stress putting everything at the top of functions and subs. Personally, I'm used to declaring my variables wherever I use them in C++ and Java, so I like to do the same thing when I'm coding in VBA. I think as long as it's not confusing, which it would be in some cases, then it's okay. Just my opinion.
 
Thanks for this feedback. I often find it very time-consuming and inefficient to travel back to the top of a sub or function every time I need to declare a new variable, so it's good to have a coder like PaultheS weigh in on this favorably. Thanks to all who participated until now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top