Default value during DIM statemetn

  • Thread starter Thread starter nath
  • Start date Start date
N

nath

Hi.

Is it possible to give a variable a default value when
you "DIM" it, for example, i want the value of a boolean
variable vis to be FALSE unless a condition is met. I
have tried Dim Vis=false as boolean. This doesnt work,
can it be done?

TIA

Nath.
 
No.

You can set a "variable" to be a constant value using the Const statement.
But to set a default value for a variable, you Dim it in one line and then
set its value in a second line.

Dim varVariable As Variant
varVariable = "Default Value"
 
On the other hand, Boolean variables is always initialized to False (and
numeric variables to 0, and string variables to "")
 
Yeah, but being an old (and I mean old) FORTRAN programmer from way back
when, the habit of always setting the default values for all variables is
just too hard to break!
 
I hear you. (I used to teach WATFIV programming)

There's also the fact that many people don't recommend relying on default
behaviours.
 
That old adage about the real result when you "assume" something ("makes an
a** out of 'u' and 'me'!).

Plus, as I often reuse variables in code for temporary things, forgetting to
always put in my own default values means that I may forget to reset an
already used variable back to a default status. Thus, except when I goof up,
I always put steps in code that set all variables to default values whenever
I'm going to use the variable in a concatenation step (Variable = Variable &
"Text"), in a summing step (Variable = Variable + 1), or in a testing step
to see if nothing has happened to the variable (If Variable = 0 Then...).

< G >
 
Back
Top