ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Prevent Overloaded variables (https://www.excelbanter.com/excel-discussion-misc-queries/192563-prevent-overloaded-variables.html)

Jeff

Prevent Overloaded variables
 
Hi,

I have some variables declared at the top of the module, so they are used
throughout the program. But here is the problem, I can redeclare the
variable inside another sub procedure, how do I prevent this? This seems
like bad feature to have in excel.

I declared option explicit at the top.

Thanks for your help.

Kevin B

Prevent Overloaded variables
 
I use a naming convention so that variables declared at the top of a molule
as constants have a 'con' prefix. So if I have a constant named conFilePath
and I need to declare a file path string variable in another sub or
funcition, in the a sub or function I use a 'str' prefix to denote a string
variable.

That would eliminate conficting names at the module, and procedure level.
--
Kevin Backmann


"Jeff" wrote:

Hi,

I have some variables declared at the top of the module, so they are used
throughout the program. But here is the problem, I can redeclare the
variable inside another sub procedure, how do I prevent this? This seems
like bad feature to have in excel.

I declared option explicit at the top.

Thanks for your help.


Dave Peterson

Prevent Overloaded variables
 
I think you should search VBA's help for: Understanding Scope and Visibility

Someday, you may appreciate the fact that you can do what you don't want to do
today.

Jeff wrote:

Hi,

I have some variables declared at the top of the module, so they are used
throughout the program. But here is the problem, I can redeclare the
variable inside another sub procedure, how do I prevent this? This seems
like bad feature to have in excel.

I declared option explicit at the top.

Thanks for your help.


--

Dave Peterson


All times are GMT +1. The time now is 08:26 AM.

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