Default value during DIM statemetn

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.
 
K

Ken Snell

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"
 
D

Douglas J. Steele

On the other hand, Boolean variables is always initialized to False (and
numeric variables to 0, and string variables to "")
 
K

Ken Snell

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!
 
D

Douglas J. Steele

I hear you. (I used to teach WATFIV programming)

There's also the fact that many people don't recommend relying on default
behaviours.
 
K

Ken Snell

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 >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top