ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Double variables initialize to zero?? (https://www.excelbanter.com/excel-programming/385871-double-variables-initialize-zero.html)

[email protected]

Double variables initialize to zero??
 
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


Jim Cone

Double variables initialize to zero??
 
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




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


John Coleman

Double variables initialize to zero??
 
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

On Mar 22, 10:01 am, "
wrote:
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





All times are GMT +1. The time now is 05:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com