= nothing vs. Is Nothing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jethro

    = nothing vs. Is Nothing

    Hi guys, quick sanity check please.

    When TESTING for nothing, it's "if <exprIs Nothing"

    when ASSIGNING, it's "<expr= Nothing"

    correct ?

    so a line "If ThisValue = nothing" in some (inherited) code is a bug, plain
    & simple ?

    Thanks

  • Armin Zingler

    #2
    Re: = nothing vs. Is Nothing

    "Jethro" <jethro_uk@hotm ail.comschrieb
    Hi guys, quick sanity check please.
    >
    When TESTING for nothing, it's "if <exprIs Nothing"
    >
    when ASSIGNING, it's "<expr= Nothing"
    >
    correct ?
    >
    so a line "If ThisValue = nothing" in some (inherited) code is a
    bug, plain & simple ?
    No, not a bug, but IMO an undesired feature. Nothing used with value
    types is the "default value" of the value type, i.e. zero for Integers,
    1/1/0001 with Dates, etc.

    "If ThisValue = nothing" only works with values types (not with
    reference types), so if ThisValue is an Integer, it is equal to "If
    ThisValue = 0"

    ....But, what about putting the caret on the word Nothing and pressing
    [F1]? ;-)


    AZ

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: = nothing vs. Is Nothing

      The nicest example is in my opinion a string

      A string that Is nothing, is not yet assigned

      A string that = nothing is the same as "" and will direct before the
      evaluating set to that if it "Is" nothing

      This finer test is not in C* languages.

      Cor




      "Jethro" <jethro_uk@hotm ail.comschreef in bericht
      news:kYmdnSbuX5 YkLb_VnZ2dnUVZ8 tuqnZ2d@bt.com. ..
      Hi guys, quick sanity check please.
      >
      When TESTING for nothing, it's "if <exprIs Nothing"
      >
      when ASSIGNING, it's "<expr= Nothing"
      >
      correct ?
      >
      so a line "If ThisValue = nothing" in some (inherited) code is a bug,
      plain
      & simple ?
      >
      Thanks
      >

      Comment

      • =?Utf-8?B?RGF2aWQgQW50b24=?=

        #4
        Re: = nothing vs. Is Nothing

        That's quite correct - with one addition: to make things a little more
        confusing, "If s = Nothing" and "If s Is Nothing" both work for strings, with
        subtly different results...
        --
        Source code converters: Convert between C#, C++, Java, VB, and Python with the most accurate and reliable source code converters

        C++ to C#
        C++ to VB
        C++ to Java
        Java to VB & C#
        Instant C#: convert VB to C#
        Instant VB: convert C# to VB
        Instant C++: VB, C#, or Java to C++/CLI


        "Armin Zingler" wrote:
        "Jethro" <jethro_uk@hotm ail.comschrieb
        Hi guys, quick sanity check please.

        When TESTING for nothing, it's "if <exprIs Nothing"

        when ASSIGNING, it's "<expr= Nothing"

        correct ?

        so a line "If ThisValue = nothing" in some (inherited) code is a
        bug, plain & simple ?
        >
        No, not a bug, but IMO an undesired feature. Nothing used with value
        types is the "default value" of the value type, i.e. zero for Integers,
        1/1/0001 with Dates, etc.
        >
        "If ThisValue = nothing" only works with values types (not with
        reference types), so if ThisValue is an Integer, it is equal to "If
        ThisValue = 0"
        >
        ....But, what about putting the caret on the word Nothing and pressing
        [F1]? ;-)
        >
        >
        AZ
        >
        >

        Comment

        • Jethro

          #5
          Re: = nothing vs. Is Nothing

          "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
          news:4F5745FF-BD74-4255-9017-40E87BAF7F64@mi crosoft.com...
          The nicest example is in my opinion a string
          >
          A string that Is nothing, is not yet assigned
          >
          A string that = nothing is the same as "" and will direct before the
          evaluating set to that if it "Is" nothing
          >
          This finer test is not in C* languages.
          >
          Cor
          >
          >
          >
          >
          "Jethro" <jethro_uk@hotm ail.comschreef in bericht
          news:kYmdnSbuX5 YkLb_VnZ2dnUVZ8 tuqnZ2d@bt.com. ..
          >Hi guys, quick sanity check please.
          >>
          >When TESTING for nothing, it's "if <exprIs Nothing"
          >>
          >when ASSIGNING, it's "<expr= Nothing"
          >>
          >correct ?
          >>
          >so a line "If ThisValue = nothing" in some (inherited) code is a bug,
          >plain
          >& simple ?
          >>
          >Thanks
          >>
          >
          The problem I was having was a test on an integer, which had a value of 0
          was equating to true ...

          Dim myInt as integer =0

          if myInt = Nothing then MessageBox("myI nt is showing as 'Nothing' even
          thought is has a vallue of 0")

          seems to print the MessageBox .....

          Comment

          • Cor Ligthert[MVP]

            #6
            Re: = nothing vs. Is Nothing

            David,

            Maybe easier, "Is" is testing a Type and "=" a value.

            While "Is" nothing means in fact no object, because everything is inheriting
            from object, this goes forever.

            Therefore it is If dr.Items("whate ver") Is DBNull.Value then the type
            DBNull.Value is tested.

            While If CInt(dr.Items(" whatever")) = 0 then the value zero is tested.

            Cor

            "David Anton" <DavidAnton@dis cussions.micros oft.comschreef in bericht
            news:831E24ED-2CEF-45D2-805A-8DE01EA3CDDC@mi crosoft.com...
            That's quite correct - with one addition: to make things a little more
            confusing, "If s = Nothing" and "If s Is Nothing" both work for strings,
            with
            subtly different results...
            --
            Source code converters: Convert between C#, C++, Java, VB, and Python with the most accurate and reliable source code converters

            C++ to C#
            C++ to VB
            C++ to Java
            Java to VB & C#
            Instant C#: convert VB to C#
            Instant VB: convert C# to VB
            Instant C++: VB, C#, or Java to C++/CLI
            >
            >
            "Armin Zingler" wrote:
            >
            >"Jethro" <jethro_uk@hotm ail.comschrieb
            Hi guys, quick sanity check please.
            >
            When TESTING for nothing, it's "if <exprIs Nothing"
            >
            when ASSIGNING, it's "<expr= Nothing"
            >
            correct ?
            >
            so a line "If ThisValue = nothing" in some (inherited) code is a
            bug, plain & simple ?
            >>
            >No, not a bug, but IMO an undesired feature. Nothing used with value
            >types is the "default value" of the value type, i.e. zero for Integers,
            >1/1/0001 with Dates, etc.
            >>
            >"If ThisValue = nothing" only works with values types (not with
            >reference types), so if ThisValue is an Integer, it is equal to "If
            >ThisValue = 0"
            >>
            >....But, what about putting the caret on the word Nothing and pressing
            >[F1]? ;-)
            >>
            >>
            >AZ
            >>
            >>

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: = nothing vs. Is Nothing

              Dim myInt as integer =0
              >
              if myInt = Nothing then MessageBox("myI nt is showing as 'Nothing' even
              thought is has a vallue of 0")
              >
              seems to print the MessageBox .....
              Yes of course because the default for an integer (Nothing) = 0,

              If 0 = 0 then ............... .... is true

              While this goes as well and is more VB style

              Dim myInt as integer
              if myInt = nothing then the messagebox will be showed, because myint is set
              forever in this case to the default 0

              Cor

              Comment

              • Karl Rhodes

                #8
                Re: = nothing vs. Is Nothing

                On 8 May, 16:46, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nlwrote :
                Dim myInt as integer =0
                >
                if myInt = Nothing then MessageBox("myI nt is showing as 'Nothing' even
                thought is has a vallue of 0")
                >
                seems to print the MessageBox .....
                >
                Yes of course because the default for an integer (Nothing) = 0,
                >
                If 0 = 0 then ............... .... is true
                >
                While this goes as well and is more VB style
                >
                Dim myInt as integer
                if myInt = nothing then the messagebox will be showed, because myint is set
                forever in this case to the default 0
                >
                Cor
                If you're using VB the why not use the IsNothing Method?

                if IsNothing(myInt ) then MessageBox.Show ....

                Comment

                • Armin Zingler

                  #9
                  Re: = nothing vs. Is Nothing

                  "Karl Rhodes" <googlegroups@c ortexa.co.uksch rieb
                  If you're using VB the why not use the IsNothing Method?
                  >
                  if IsNothing(myInt ) then MessageBox.Show ....
                  Why call a function that does the comparision instead of doing the
                  comparison?


                  Armin

                  Comment

                  • Jethro

                    #10
                    Re: = nothing vs. Is Nothing

                    "Karl Rhodes" <googlegroups@c ortexa.co.ukwro te in message
                    news:c1bcba36-f2a2-4065-9479-7f60575f232f@r6 6g2000hsg.googl egroups.com...
                    On 8 May, 16:46, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nlwrote :
                    Dim myInt as integer =0
                    >>
                    if myInt = Nothing then MessageBox("myI nt is showing as 'Nothing' even
                    thought is has a vallue of 0")
                    >>
                    seems to print the MessageBox .....
                    >>
                    >Yes of course because the default for an integer (Nothing) = 0,
                    >>
                    >If 0 = 0 then ............... .... is true
                    >>
                    >While this goes as well and is more VB style
                    >>
                    >Dim myInt as integer
                    >if myInt = nothing then the messagebox will be showed, because myint is
                    >set
                    >forever in this case to the default 0
                    >>
                    >Cor
                    >
                    If you're using VB the why not use the IsNothing Method?
                    >
                    if IsNothing(myInt ) then MessageBox.Show ....

                    As I said, inherited code...

                    Comment

                    • Cor Ligthert[MVP]

                      #11
                      Re: = nothing vs. Is Nothing

                      >
                      As I said, inherited code...
                      No you said,
                      >so a line "If ThisValue = nothing" in some (inherited) code is a bug,
                      plain & simple ?

                      The "Is" is about objects, while you can test everything as object, as that
                      is the base for every class in Net.
                      (The so often used ToString is a method from object and therefore a method
                      from everything).

                      If this Value = nothing has nothing to do with inherited code.

                      However why did you get the idea that this is a bug?

                      Cor

                      Comment

                      • Jethro

                        #12
                        Re: = nothing vs. Is Nothing

                        "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                        news:39F15764-FA45-482B-8380-C33186A49AEF@mi crosoft.com...
                        >
                        >>
                        >As I said, inherited code...
                        >
                        No you said,
                        >
                        so a line "If ThisValue = nothing" in some (inherited) code is a bug,
                        plain & simple ?
                        >
                        The "Is" is about objects, while you can test everything as object, as
                        that is the base for every class in Net.
                        (The so often used ToString is a method from object and therefore a method
                        from everything).
                        >
                        If this Value = nothing has nothing to do with inherited code.
                        >
                        However why did you get the idea that this is a bug?
                        ROTFL !

                        Sorry, bad choice of words. What I meant is that I have just started a new
                        job, and am picking up the code left by the previous developer - therefore
                        *I* "inherited" it.

                        Nice to go home with a laugh - thanks for your input, hope you have a good
                        weekend !

                        Comment

                        Working...