Results 1 to 3 of 3

Thread: Null value for variables

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2004
    Posts
    70

    Null value for variables

    Hey I'm trying to check if a variable has a value assigned or not.

    Dim var as Integer

    If var=Null then
    ...
    else
    ...
    end if

    But it seems that Null doesn't exist, and 'Nothing' isn't quite the same as for an integer Nothing=0.

    Any ideas? thanks.

  2. #2
    Addicted Member
    Join Date
    Nov 2004
    Posts
    171

    Re: Null value for variables

    I believe an integer is automatically 0 when not initiated, but wouldn't null just be an empty set ("")?
    Sherminator ~ I'll be back.

  3. #3
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Null value for variables

    Nothing is when the object hasn't been initialised i.e.

    Code:
    Dim NewClass as Class1
    
    If NewClass Is Nothing Then
        'NewClass is Nothing because it hasn't been initialized yet.
    End If
    
    'Whereas
    Dim NewClass as New Class1
    
    If NewClass Is Nothing Then
    
    Else
        'NewClass is not Nothing because it has been initialized.
    End If
    A string is always an empty string, which is not nothing. An Integer or any variation of it will always be 0 is it hasn't been set.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width