Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-01-2009
Member
 
Join Date: Jan 2009
Posts: 8
Difference between "isNull" and "is Nothing" in VB

Hi again,

could anyone explain the difference bewtten IsNull(varname) and varname is Nothing.

I have a function that returns null, yet using IsNull() to check the return value does not work and is nothing does detect the null correctly.

So if "is nothing" checks for a null what does IsNull() check for??
Reply With Quote
  #2  
Old 02-01-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Difference between "isNull" and "is Nothing" in VB

In VB you compare an uninitialized variant to an uninitialized integer? It seems sensible that the comparison would return True, and it does. Empty compares as equal to 0 and the empty string, which might cause false positives in our example above. If you need to detect whether a variable actually is an empty variant and not a string or a number, you can use IsEmpty. (Alternatively, you could use TypeName or VarType, but I prefer IsEmpty.)


Nothing is similar to Empty but subtly different. Empty says "I am an uninitialized variant", Nothing says "I am an object reference that refers to no object". Since the equality operator on objects checks for equality on the default property of an object, any attempt to say If Blah = Nothing Then is doomed to failure -- Nothing does not have a default property, so this will produce a run-time error. To check to see if an object reference is invalid, use If Blah Is Nothing Then.


Null is weirder still. The semantics of Null are very poorly understood, particularly amongst people who have little experience with relational databases. Empty says "I'm an uninitialized variant", Nothing says "I'm an invalid object" and Null says "I represent a value which is not known."
Reply With Quote
  #3  
Old 02-01-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Difference between "isNull" and "is Nothing" in VB

Nothing is different to Null

Nothing is used with object varibles
Set ojbVar = Nothing

Null is used with string varibles etc
strVar = Null


isEmpty() does not mean an empty string, as a string with "" in it, is not acctually empty, and empty string = Null.
Try
If len(strVar) = 0 Then...
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Difference between "isNull" and "is Nothing" in VB"
Thread Thread Starter Forum Replies Last Post
msiexec.exe Application Error "The instruction at "0x00f33fe8" referenced memory at "0x00f33fe8". The memory could not be "written"." haritable Office Setup 3 10-01-2014 10:40 AM
<input type="button" value="Enregistrer" onclick="location.href=../asp/PRaces.asp"> Luz Software Development 6 18-05-2010 12:27 AM
Difference between "Junction points" and "Hard Links" ? Carla Lacrosse Windows XP Support 7 02-03-2009 01:51 AM
Difference between "Recycler" and "recycled" folder? Deleteable when Recycle Bin NOT used for this partition ? Eugen Austermann Windows XP Support 6 11-12-2007 03:08 AM
Adding commands to "Folder Options/Edit File Type/Actions" grayed-out "Edit" & "Remove" Green_XP Windows XP Support 1 06-11-2007 02:18 PM


All times are GMT +5.5. The time now is 02:35 PM.