vbNullString

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

    vbNullString

    What's the .NET equivalent

    Dim strTmp as string
    If strTmp=vbNullSt ring

    Posted this earlier in the wrong Newsgroup.


  • Phill W.

    #2
    Re: vbNullString

    Lou wrote:
    What's the .NET equivalent?
    Dim strTmp as string
    If strTmp = vbNullString
    As given, I'm not sure you can do this comparison.
    Can a String hold a "database-y" null value? (As opposed to a proper
    Nothing?)

    Well anyway, an Object can, so

    Dim o as Object _
    = PotentiallyNull ValueFromDB()

    If o Is System.DBNull.V alue Then
    . . .

    HTH,
    Phill W.

    Comment

    • =?ISO-8859-1?Q?G=F6ran_Andersson?=

      #3
      Re: vbNullString

      Lou wrote:
      What's the .NET equivalent
      >
      Dim strTmp as string
      If strTmp=vbNullSt ring
      >
      Posted this earlier in the wrong Newsgroup.
      >
      >
      String.Empty

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • =?ISO-8859-1?Q?G=F6ran_Andersson?=

        #4
        Re: vbNullString

        Phill W. wrote:
        Lou wrote:
        >What's the .NET equivalent?
        >
        >Dim strTmp as string
        >If strTmp = vbNullString
        >
        As given, I'm not sure you can do this comparison.
        Can a String hold a "database-y" null value? (As opposed to a proper
        Nothing?)
        >
        Well anyway, an Object can, so
        >
        Dim o as Object _
        = PotentiallyNull ValueFromDB()
        >
        If o Is System.DBNull.V alue Then
        . . .
        >
        HTH,
        Phill W.
        vbNullString doesn't represent a database null, it's just an empty string.

        --
        Göran Andersson
        _____
        Göran Anderssons privata hemsida.

        Comment

        • =?ISO-8859-1?Q?G=F6ran_Andersson?=

          #5
          Re: vbNullString

          Göran Andersson wrote:
          Lou wrote:
          >What's the .NET equivalent
          >>
          >Dim strTmp as string
          >If strTmp=vbNullSt ring
          >>
          >Posted this earlier in the wrong Newsgroup.
          >>
          >
          String.Empty
          >
          Addition:

          To check if the string is empty, you should rather check if the length
          is zero than to do a string comparison.

          --
          Göran Andersson
          _____
          Göran Anderssons privata hemsida.

          Comment

          • rowe_newsgroups

            #6
            Re: vbNullString

            On Mar 6, 12:51 pm, "Lou" <lou.gar...@com cast.netwrote:
            What's the .NET equivalent
            >
            Dim strTmp as string
            If strTmp=vbNullSt ring
            >
            Posted this earlier in the wrong Newsgroup.
            I like using String.IsNullOr Empty(...) - as it returns a boolean value
            indicating if the string is *gasp* null or empty :-).

            So your code could be replaced by:

            Dim strTmp as String
            If String.IsNullOr Empty(strTmp) Then
            ' blah blah blah
            End If

            Thanks,

            Seth Rowe

            Comment

            • Rad [Visual C# MVP]

              #7
              Re: vbNullString

              On Tue, 06 Mar 2007 21:20:01 +0100, Göran Andersson wrote:
              Lou wrote:
              >What's the .NET equivalent
              >>
              >Dim strTmp as string
              >If strTmp=vbNullSt ring
              >>
              >Posted this earlier in the wrong Newsgroup.
              >>
              >
              String.Empty
              Not true. String.Empty equates to "", the zero length string. The MSDN
              documentation specifically states that vbNullString is not the same as a
              zero-length string.

              I think the closest thing would be nothing
              --
              Bits.Bytes

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: vbNullString

                "Göran Andersson" <guffa@guffa.co mschrieb:
                vbNullString doesn't represent a database null, it's just an empty string.
                It's a string pointer with value 0 in VB6, primarily used when calling Win32
                API functions.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                  #9
                  Re: vbNullString

                  Rad [Visual C# MVP] wrote:
                  On Tue, 06 Mar 2007 21:20:01 +0100, Göran Andersson wrote:
                  >
                  >Lou wrote:
                  >>What's the .NET equivalent
                  >>>
                  >>Dim strTmp as string
                  >>If strTmp=vbNullSt ring
                  >>>
                  >>Posted this earlier in the wrong Newsgroup.
                  >>>
                  >String.Empty
                  >
                  Not true. String.Empty equates to "", the zero length string. The MSDN
                  documentation specifically states that vbNullString is not the same as a
                  zero-length string.
                  >
                  I think the closest thing would be nothing
                  You are right. There seems to be a lot of confusion out there. I found
                  advice to use vbNullString instead of "", but then that is not good
                  advice at all, as they have completely different uses.

                  I checked the implementation of vbNullString in the
                  Microsoft.Visua lBasic library, and it's a constant string with the value
                  Nothing, so it's exactly the same as Nothing.

                  --
                  Göran Andersson
                  _____
                  Göran Anderssons privata hemsida.

                  Comment

                  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                    #10
                    Re: vbNullString

                    Herfried K. Wagner [MVP] wrote:
                    "Göran Andersson" <guffa@guffa.co mschrieb:
                    >vbNullString doesn't represent a database null, it's just an empty
                    >string.
                    >
                    It's a string pointer with value 0 in VB6, primarily used when calling
                    Win32 API functions.
                    >
                    Yes, you are right.

                    I searched for how vbNullString was used, and came to the conclusion
                    that it was an empty string, but most of what I found appearently was
                    written by people more confused than I was...

                    --
                    Göran Andersson
                    _____
                    Göran Anderssons privata hemsida.

                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: vbNullString

                      Herfried,
                      It's a string pointer with value 0 in VB6, primarily used when calling
                      Win32 API functions.
                      >
                      Do you mean
                      "0"
                      or
                      a pointer to computer memory address zero
                      or (as I assume)
                      a not yet set pointer (represented in VB.Net by the keyword Nothing)

                      Cor


                      Comment

                      • Branco Medeiros

                        #12
                        Re: vbNullString

                        Cor Ligthert [MVP] wrote:
                        <snip>
                        a pointer to computer memory address zero
                        or (as I assume)
                        a not yet set pointer (represented in VB.Net by the keyword Nothing)
                        <snip>

                        Which, AFAIK, happen to be exactly the same thing.

                        A pointer to the computer memory address 0 has the value of 0 (a
                        pointer, I suppose you know, *is* the value it points to), and a "not
                        yet set pointer" is exactly this, a reference value which was set to 0
                        -- upon initialization by the VB compiler generated code -- to mean
                        what other languages call "Null" and we call Nothing.

                        It became a convention to treat pointers (our "reference values") that
                        reference the special (and invalid) address 0 as non-initialized,
                        which is not exactly true: the pointer *was* initialized but to a
                        value known to be unusable.

                        Historically VB was one of the languages that always enforced this
                        notion, initializing the stack area to 0 and thus setting local
                        variables to a default, known value: 0, false, Nothing, etc. If
                        someone thinks this is not a big deal, compare it to Delphi, which
                        doesn't do this and requires you to initialize each and every local
                        variable before use (which is a major pain, and after you've done that
                        a zillion times you start looking for the compiler switch that
                        initializes the variables for you -- but there's none). C and C++ do
                        the same, but most compilers only warn you of the non-initilizion,
                        while others don't even bother to, so the programmer can happily use
                        values set to whatever was in the variable address at run time and
                        become appalled when things go awry with his/her code...

                        Uh, I guess I'm heavilly drifting to OT land now...

                        Regards,

                        Branco.

                        Comment

                        • Cor Ligthert [MVP]

                          #13
                          Re: vbNullString

                          >
                          Uh, I guess I'm heavilly drifting to OT land now...
                          >
                          I don't think so, in my opinion does your text add quiet a bit to the
                          thread.

                          Cor


                          Comment

                          • Herfried K. Wagner [MVP]

                            #14
                            Re: vbNullString

                            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                            >It's a string pointer with value 0 in VB6, primarily used when calling
                            >Win32 API functions.
                            >>
                            Do you mean
                            "0"
                            or
                            a pointer to computer memory address zero
                            '(LP<...>STR)0' in C, so a pointer to a memory address.

                            --
                            M S Herfried K. Wagner
                            M V P <URL:http://dotnet.mvps.org/>
                            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                            Comment

                            Working...