Sunday, November 14, 2010

How can I check to see if a variable is null in VB?

I want to check if a variable is null. Apparently...



If var1 Is Not Null Then



is no longer supported.How can I check to see if a variable is null in VB?
The IsNot operator in VB.net is your best bet:



if myVar IsNot Nothing then

...

end if



It is the most portable, IsNull relies on Microsoft.VisualBasic.dll and this is just plain illogical:



if Not myVar Is Nothing

...

end if



Spock would be most displeased. Live long and prosper!How can I check to see if a variable is null in VB?
If var1 %26lt;%26gt; Null



(If I remember correctly)
Try this:



if var1 %26lt;%26gt; '; '; then (no space between quotes)
If liname.Text IsNot Nothing Then

DoSomething

EndIf
if not ( var is nothing) then

'whatever

End if
If IsDBNull(foo) Then

...

End If
hi for vb try this

if not(isnull(myvar) then

......

end if

bye for now
I believe it is the following:



If Isnull(Var1) = True then

No comments:

Post a Comment