Static i as integer
What will i be before I assign a value.
It seems to be just zero (0) but I wanted to confirm that.
Static i as integer
What will i be before I assign a value.
It seems to be just zero (0) but I wanted to confirm that.
Variables of all VB data types receive their respective default value when the procedure starts.
This includes initializing all numbers to zero, and all the other data types to their flavour of zero (vbNullString
for strings, not exactly the same as an empty string ""
, False
for booleans, Empty
for variants, and Nothing
for objects).
? vbNullstring = ""
evaluates to True
. So, maybe not exactly the same as an empty string, in the same sense that a constant isn't exactly the same as its value. But for all practical purposes, I would say that they are exactly the same, since they are interchangeable in code. –
Grindle =
evaluates to True
not only when the two things are the same, but also when they can be coerced to something else that can be seen as same. E.g. ? False = 0
or ? False = Empty
all give True
even though they are not the same, rather, they all are falsy. vbNullString
is different though, because it has the same type as ""
(String
), and they are actually the same if you are only interested in comparing their content, but sometimes you want to know more. –
Brindled vbNullString
vs. ""
to some methods, properties, etc. In some cases passing vbNullString
can even cause a null pointer exception. –
Botsford Normally in Visual Basic, when a static variable is declared inside a Function or Sub procedure, it gets initialized to 0 (numeric data type) or an empty string, "" (string data type), by default.
So yeah, you can be sure it's default value is zero.
Hope this helps
© 2022 - 2024 — McMap. All rights reserved.
Static
in VB6 has an entirely different meaning from its meaning in .Net. A static variable is a local variable that retains its value between method calls. In other words, it has the scope of a local variable but the lifetime of a module-level variable. – Grindle