Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a variable is null

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
hallo,
how do I check if a variable is null?

thanks

 
If you want to check to see if its null from a database read use

if isdbnull(value) then ...

Otherwise use

if value is nothing then...
 
thanks shatch,

my variable is an integer type and doesn't come from a database. If I use the "is nothing" I get this error:

'Is' requires operands that have reference types, but this operand has the value type 'Integer'.

Any suggestion?
 
ehm.... I found out:

instead of "is nothing" it would become "= nothing" if the variable is an integer.
 
Yeah, and its also worth noting that nothing equates to 0 (zero) when dealing with integers
 
gulp, I didn't know that. Actually this is a behaviour that I would prefer to avoid.
Do you know a way to find out if an integer value is null, but distinguished from 0?

thanks
 
You can set an integer to DBNull (SQL null essentially) if you wish -

Dim myInt as integer = DBNull.Value

which is what a null integer coming from a database would be set to. if you are just coding, and not using a database, you could just manually set the integer to -1 and assume that as null, it really depends on the application though.

 
shatch thanks for the hint,
I think I'll have to use the -1 trick and "pretend" that is a null value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top