Re: Declarations variables, Dim, some guidance please
- From: "Bob Phillips" <bob.phillips@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 00:37:21 +0100
"Neal Zimm" <nealzimm@xxxxxxxxx> wrote in message
news:AEBDB225-BCB4-4A42-90DF-EF3175949C17@xxxxxxxxxxxxxxxx
> 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.
Personally, I try and keep this to a minimum, as it is always possible that
in a procedure the variable will have a residual value from a previous
procedure, preferring to use arguments. Yes, I know we should always
initialise, but it is too easy to be lazy and rely on the default initial
value.
The pros and the cons are the same things really, they keep the value across
procedures, they have (at least) module scope, and so on, it would depend
upon the application as to whether that is a pro or a con. What I am saying
I guess is that each variablke should be carefully considerred before either
placing in Declarations or a procedure.
> 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?
Because it is not a duplicate. The first was a module scope variable, the
second was a procedure scope variable, it is quite legitimate to have both.
When you do, when in the procedure with the procedure scope variable will
be the one used, as you experienced.
.
- Follow-Ups:
- Re: Declarations variables, Dim, some guidance please
- From: Neal Zimm
- Re: Declarations variables, Dim, some guidance please
- From: STEVE BELL
- 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: How to use ADO to issue query that more than 250 characters?
- Next by Date: Need Help Using cards.dll with Excel VBA
- Previous by thread: Re: Declarations variables, Dim, some guidance please
- Next by thread: Re: Declarations variables, Dim, some guidance please
- Index(es):
Relevant Pages
|