Results 1 to 3 of 3

Thread: Difference between "isNull" and "is Nothing" in VB

  1. #1
    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??

  2. #2
    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."

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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...

Similar Threads

  1. Replies: 3
    Last Post: 10-01-2014, 10:40 AM
  2. Replies: 6
    Last Post: 18-05-2010, 12:27 AM
  3. Difference between "Junction points" and "Hard Links" ?
    By Carla Lacrosse in forum Windows XP Support
    Replies: 7
    Last Post: 02-03-2009, 01:51 AM
  4. Replies: 6
    Last Post: 11-12-2007, 03:08 AM
  5. Replies: 1
    Last Post: 06-11-2007, 02:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,586,140.87589 seconds with 17 queries