L
Lars Brownies
How can I check if a variable already has a value or if it's still blank?
Thanks,
Lars
Thanks,
Lars
Lars said:How can I check if a variable already has a value or if it's still blank?
Thanks,
Lars
Banana said:Depends on what the data type is.
If we're talking about primitive data types (e.g. string, integers,
double, date), then they have a default initial value (e.g. "", 0, 0,
1899-12-31, respectively)
You could test for those values but be aware they could have been assigned
a new value that is same as the default value and you would have no way to
know, unless you check the source where you set the new value.
For objects such as DAO/ADO Recordset, Excel.Application, they are
initially given a Empty value. You test an object variable with IsEmpty().
Note that IsEmpty will succeed even if the object has been set to nothing
because Nothing is not same thing as Empty.
HTH.
Banana said:For objects such as DAO/ADO Recordset, Excel.Application, they are
initially given a Empty value. You test an object variable with IsEmpty().
Note that IsEmpty will succeed even if the object has been set to nothing
because Nothing is not same thing as Empty.
Dirk said:You are mistaken here, or else I am misunderstanding what you are trying
to say. Object variables initially have a value of Nothing, and IsEmpty
will report False for an unassigned object variable.
this usually works...
If NZ(trim(myvariable),vbnullstring) = vbnullstring then ...
<its has no value>
else
<it has a value>
end if
if Len()=0.
Lars said:Why is this better than
if str = ""
?
Thanks,
Lars
Why is this better than
if str = ""
I did a quick test with the code beneath where the multiple
<if str = ""> takes 34 seconds and the multiple <if len(str) = 0>
takes 15
seconds. That is with billion repitions.