Re: Declarations variables, Dim, some guidance please
- From: "Jake Marx" <msnews@xxxxxxxxxxxx>
- Date: Mon, 15 Aug 2005 15:57:57 -0700
Ni Neal,
Neal Zimm wrote:
In an application that I'm developing I have dim'd quite a few variables in Declarations. I'll admit some of it is not wanting to take the time to put those vars that are used quite often in many macros within the sub SubName(var list) parenthesis.
1) What advice can you offer on the pro's and cons of this technique? All of the application's code is in ONE module.
I don't like to declare variables at module level or globally (Public keyword in standard module) unless I have to. Some reasons are readability, ease of maintenance, and knowing your variables won't be "trounced upon" by various procedures. Module-level and global variables will also use more resources.
The alternative is to pass variables via arguments to functions/subroutines. It is undoubtedly more work upfront, but IMO it pays off to do it this way.
2) I got 'bitten' when testing a macro where a var called Draw was dim'd as integer in Declarations, had a good value > 0 in prior macros, but was 0 in the macro I was testing.
Sure enough, I had dim'd it again, inadvertantly, also as Integer in the macro being tested. Hence the 0 value, I guess. The QUESTION is, why did I NOT get a duplicate Dim error?
Well, since the variables had different scopes, it wasn't a duplicate declaration. You had one module-level variable named Draw, and you had a local variable named Draw with a completely different value.
-- Regards,
Jake Marx MS MVP - Excel www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]
.
- Follow-Ups:
- Re: Declarations variables, Dim, some guidance please
- From: Neal Zimm
- Re: Declarations variables, Dim, some guidance please
- References:
- Declarations variables, Dim, some guidance please
- From: Neal Zimm
- Declarations variables, Dim, some guidance please
- Prev by Date: Re: Macro creates additional datafiles when saving copies of workbook
- Next by Date: Re: Alignment
- Previous by thread: Re: Declarations variables, Dim, some guidance please
- Next by thread: Re: Declarations variables, Dim, some guidance please
- Index(es):
Relevant Pages
|
Loading