Double variables initialize to zero??

M

markjerz

Hi,

I've got an array of doubles and i want to check that they have not
been initialized.

However, the following code returns a message box with false and
outputting the variable foo gives 0.
Is this behaviour intended, how can I work around it?

Thanks,
Mark

sub test()

dim foo as double
msgbox isnull(foo)

end sub
 
J

Jim Cone

Mark,
When a procedure begins running, a numeric variable is initialized to zero
and Variant variables are initialized to Empty.
IsNull can be misleading as it will only tell you the if the condition that exists
is the absence of any value. For instance... IsNull(CheckBox1.Value).
Note that empty, zero and "" are not null conditions.

However, if are you asking if an array has been dimensioned? Then ...
Sub ReadyOrNot()
Dim d() As Double
Dim blnReady As Boolean
' ReDim d(0 To 1000)
On Error Resume Next
blnReady = UBound(d) > -9999999
On Error GoTo 0
MsgBox blnReady
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



<[email protected]>
wrote in message
Hi,
I've got an array of doubles and i want to check that they have not
been initialized.
However, the following code returns a message box with false and
outputting the variable foo gives 0.
Is this behaviour intended, how can I work around it?
Thanks,
Mark

sub test()
dim foo as double
msgbox isnull(foo)
end sub
 
J

John Coleman

In addition to Jim's idea of using a variant which is later
initialized (dimensioned) to be an array, another possible work-around
is to maintain a boolean flag (which is automatically initialized to
false) and set the flag equal to true when the initialization code is
run.

Hth,

John Coleman
 

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