CStr() vs. .ToString()

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

    CStr() vs. .ToString()

    Book I am reading says that Cstr() is best method for efficency and safety
    however it doesnt compare that method of the .ToString() method.

    Which is best.

    Thanks


  • Scott M.

    #2
    Re: CStr() vs. .ToString()

    IMHO (and this has been debated for quite some time now), you should view
    all of the old "data-type" specific functions as legacy functions and no
    longer use them. Instead, use the more object-oriented methods of a type.

    CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or .ToString
    All date/time functions would be replaced with methods and properties of the
    Date class
    All string functions would be replaced with methods and properties of the
    String class.

    et all.


    "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
    news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=blue]
    > Book I am reading says that Cstr() is best method for efficency and safety
    > however it doesnt compare that method of the .ToString() method.
    >
    > Which is best.
    >
    > Thanks
    >
    >[/color]


    Comment

    • guy

      #3
      Re: CStr() vs. .ToString()

      both points of view are valid, however i use the vb string methods as the
      compiler makes optimzations that can improve performance over the native .Net
      methods, also i find the vb methods read better.

      cheers

      guy

      "Scott M." wrote:
      [color=blue]
      > IMHO (and this has been debated for quite some time now), you should view
      > all of the old "data-type" specific functions as legacy functions and no
      > longer use them. Instead, use the more object-oriented methods of a type.
      >
      > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or .ToString
      > All date/time functions would be replaced with methods and properties of the
      > Date class
      > All string functions would be replaced with methods and properties of the
      > String class.
      >
      > et all.
      >
      >
      > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
      > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=green]
      > > Book I am reading says that Cstr() is best method for efficency and safety
      > > however it doesnt compare that method of the .ToString() method.
      > >
      > > Which is best.
      > >
      > > Thanks
      > >
      > >[/color]
      >
      >
      >[/color]

      Comment

      • Sean

        #4
        Re: CStr() vs. .ToString()

        for my clarification
        ..ToString() = native .Net methods
        CStr() = vb String methods?

        from my understanding in the book I am reading Cstr() etc is the perfered
        way however it doesnt address .ToString()

        "guy" wrote:
        [color=blue]
        > both points of view are valid, however i use the vb string methods as the
        > compiler makes optimzations that can improve performance over the native .Net
        > methods, also i find the vb methods read better.
        >
        > cheers
        >
        > guy
        >
        > "Scott M." wrote:
        >[color=green]
        > > IMHO (and this has been debated for quite some time now), you should view
        > > all of the old "data-type" specific functions as legacy functions and no
        > > longer use them. Instead, use the more object-oriented methods of a type.
        > >
        > > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or .ToString
        > > All date/time functions would be replaced with methods and properties of the
        > > Date class
        > > All string functions would be replaced with methods and properties of the
        > > String class.
        > >
        > > et all.
        > >
        > >
        > > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
        > > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=darkred]
        > > > Book I am reading says that Cstr() is best method for efficency and safety
        > > > however it doesnt compare that method of the .ToString() method.
        > > >
        > > > Which is best.
        > > >
        > > > Thanks
        > > >
        > > >[/color]
        > >
        > >
        > >[/color][/color]

        Comment

        • Scott M.

          #5
          Re: CStr() vs. .ToString()


          "guy" <guy@discussion s.microsoft.com > wrote in message
          news:2199BA10-0B41-4D7D-B7AF-F34D469457BD@mi crosoft.com...[color=blue]
          > both points of view are valid, however i use the vb string methods as the
          > compiler makes optimzations that can improve performance over the native
          > .Net
          > methods, also i find the vb methods read better.[/color]

          The VB 6.0 way are not methods, they are functions. The .NET way are object
          methods. The VB.NET compiler does NOT optimize the VB 6.0 functions to work
          BETTER than the natvie .NET object methods.

          To answer your question, ToString would be my suggestion, rather than
          CStr(). ToString is a method of the Object Type, and since all classes
          inherit from Object, all objects have this method.

          [color=blue]
          >
          > cheers
          >
          > guy
          >
          > "Scott M." wrote:
          >[color=green]
          >> IMHO (and this has been debated for quite some time now), you should view
          >> all of the old "data-type" specific functions as legacy functions and no
          >> longer use them. Instead, use the more object-oriented methods of a
          >> type.
          >>
          >> CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
          >> .ToString
          >> All date/time functions would be replaced with methods and properties of
          >> the
          >> Date class
          >> All string functions would be replaced with methods and properties of the
          >> String class.
          >>
          >> et all.
          >>
          >>
          >> "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
          >> news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=darkred]
          >> > Book I am reading says that Cstr() is best method for efficency and
          >> > safety
          >> > however it doesnt compare that method of the .ToString() method.
          >> >
          >> > Which is best.
          >> >
          >> > Thanks
          >> >
          >> >[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          • CMM

            #6
            Re: CStr() vs. .ToString()

            I don't think that's true at all. First off, CStr,CBool, Etc. are all just
            easier-to-read specialized wrappers around CType..... which in and of itself
            is a special "VB" construct. The true "non-VB" casting operator is
            DirectCast(...) .

            Contrary to what Scott M says you're SUPPOSED to use them. What's the point
            of using VB if you're not going to use its special methods that make your
            life easier? This is straight from the VB documentation:

            "As a rule, you should use the Visual Basic type conversion functions in
            preference to the .NET Framework methods such as ToString(), either on the
            Convert class or on an individual type structure or class. The Visual Basic
            functions are designed for optimal interaction with Visual Basic code, and
            they also make your source code shorter and easier to read. In addition, the
            ..NET Framework conversion methods do not always produce the same results as
            the Visual Basic functions, for example when converting Boolean to Integer.
            For more information, see Troubleshooting Data Types."

            In addition, although I'm a guy who always initializes strings and objects
            as soon as possible rather than have them sit around until my algorithm uses
            them- so I don't really care about the following- but, there's an advantage
            to using VB's functions: they interpret "Nothing." You can't use the OO
            methods on a string that is "Nothing" (s.ToUpper for instance won't work).

            --
            -C. Moya

            "Scott M." <s-mar@nospam.nosp am> wrote in message
            news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...[color=blue]
            > IMHO (and this has been debated for quite some time now), you should view
            > all of the old "data-type" specific functions as legacy functions and no
            > longer use them. Instead, use the more object-oriented methods of a type.
            >
            > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
            > .ToString
            > All date/time functions would be replaced with methods and properties of
            > the Date class
            > All string functions would be replaced with methods and properties of the
            > String class.
            >
            > et all.
            >
            >
            > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
            > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=green]
            >> Book I am reading says that Cstr() is best method for efficency and
            >> safety
            >> however it doesnt compare that method of the .ToString() method.
            >>
            >> Which is best.
            >>
            >> Thanks
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Bob Lehmann

              #7
              Re: CStr() vs. .ToString()

              >> You can't use the OO methods on a string that is "Nothing"

              Why would you want to?

              Oh, I get it, you're too lazy to check the data before performing an
              operation it. Isn't checking your data a 100 level concept?

              I'm guessing that On Error Resume Next is one of your friends too.

              Bob Lehmann

              "CMM" <cmm@nospam.com > wrote in message
              news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...[color=blue]
              > I don't think that's true at all. First off, CStr,CBool, Etc. are all just
              > easier-to-read specialized wrappers around CType..... which in and of[/color]
              itself[color=blue]
              > is a special "VB" construct. The true "non-VB" casting operator is
              > DirectCast(...) .
              >
              > Contrary to what Scott M says you're SUPPOSED to use them. What's the[/color]
              point[color=blue]
              > of using VB if you're not going to use its special methods that make your
              > life easier? This is straight from the VB documentation:
              >
              > "As a rule, you should use the Visual Basic type conversion functions in
              > preference to the .NET Framework methods such as ToString(), either on the
              > Convert class or on an individual type structure or class. The Visual[/color]
              Basic[color=blue]
              > functions are designed for optimal interaction with Visual Basic code, and
              > they also make your source code shorter and easier to read. In addition,[/color]
              the[color=blue]
              > .NET Framework conversion methods do not always produce the same results[/color]
              as[color=blue]
              > the Visual Basic functions, for example when converting Boolean to[/color]
              Integer.[color=blue]
              > For more information, see Troubleshooting Data Types."
              >
              > In addition, although I'm a guy who always initializes strings and objects
              > as soon as possible rather than have them sit around until my algorithm[/color]
              uses[color=blue]
              > them- so I don't really care about the following- but, there's an[/color]
              advantage[color=blue]
              > to using VB's functions: they interpret "Nothing." You can't use the OO
              > methods on a string that is "Nothing" (s.ToUpper for instance won't work).
              >
              > --
              > -C. Moya
              > www.cmoya.com
              > "Scott M." <s-mar@nospam.nosp am> wrote in message
              > news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...[color=green]
              > > IMHO (and this has been debated for quite some time now), you should[/color][/color]
              view[color=blue][color=green]
              > > all of the old "data-type" specific functions as legacy functions and no
              > > longer use them. Instead, use the more object-oriented methods of a[/color][/color]
              type.[color=blue][color=green]
              > >
              > > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
              > > .ToString
              > > All date/time functions would be replaced with methods and properties of
              > > the Date class
              > > All string functions would be replaced with methods and properties of[/color][/color]
              the[color=blue][color=green]
              > > String class.
              > >
              > > et all.
              > >
              > >
              > > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
              > > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...[color=darkred]
              > >> Book I am reading says that Cstr() is best method for efficency and
              > >> safety
              > >> however it doesnt compare that method of the .ToString() method.
              > >>
              > >> Which is best.
              > >>
              > >> Thanks
              > >>
              > >>[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Martin

                #8
                Re: CStr() vs. .ToString()

                Wow, what happened to put you in this mood?
                Checking if a variable actually contains data before doing a convert to
                upper case is simply too much code. If you can avoid that it makes the code
                a lot better readable.


                "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...[color=blue][color=green][color=darkred]
                >>> You can't use the OO methods on a string that is "Nothing"[/color][/color]
                >
                > Why would you want to?
                >
                > Oh, I get it, you're too lazy to check the data before performing an
                > operation it. Isn't checking your data a 100 level concept?
                >
                > I'm guessing that On Error Resume Next is one of your friends too.
                >
                > Bob Lehmann
                >
                > "CMM" <cmm@nospam.com > wrote in message
                > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...[color=green]
                >> I don't think that's true at all. First off, CStr,CBool, Etc. are all
                >> just
                >> easier-to-read specialized wrappers around CType..... which in and of[/color]
                > itself[color=green]
                >> is a special "VB" construct. The true "non-VB" casting operator is
                >> DirectCast(...) .
                >>
                >> Contrary to what Scott M says you're SUPPOSED to use them. What's the[/color]
                > point[color=green]
                >> of using VB if you're not going to use its special methods that make your
                >> life easier? This is straight from the VB documentation:
                >>
                >> "As a rule, you should use the Visual Basic type conversion functions in
                >> preference to the .NET Framework methods such as ToString(), either on
                >> the
                >> Convert class or on an individual type structure or class. The Visual[/color]
                > Basic[color=green]
                >> functions are designed for optimal interaction with Visual Basic code,
                >> and
                >> they also make your source code shorter and easier to read. In addition,[/color]
                > the[color=green]
                >> .NET Framework conversion methods do not always produce the same results[/color]
                > as[color=green]
                >> the Visual Basic functions, for example when converting Boolean to[/color]
                > Integer.[color=green]
                >> For more information, see Troubleshooting Data Types."
                >>
                >> In addition, although I'm a guy who always initializes strings and
                >> objects
                >> as soon as possible rather than have them sit around until my algorithm[/color]
                > uses[color=green]
                >> them- so I don't really care about the following- but, there's an[/color]
                > advantage[color=green]
                >> to using VB's functions: they interpret "Nothing." You can't use the OO
                >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                >> work).
                >>
                >> --
                >> -C. Moya
                >> www.cmoya.com
                >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...[color=darkred]
                >> > IMHO (and this has been debated for quite some time now), you should[/color][/color]
                > view[color=green][color=darkred]
                >> > all of the old "data-type" specific functions as legacy functions and
                >> > no
                >> > longer use them. Instead, use the more object-oriented methods of a[/color][/color]
                > type.[color=green][color=darkred]
                >> >
                >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                >> > .ToString
                >> > All date/time functions would be replaced with methods and properties
                >> > of
                >> > the Date class
                >> > All string functions would be replaced with methods and properties of[/color][/color]
                > the[color=green][color=darkred]
                >> > String class.
                >> >
                >> > et all.
                >> >
                >> >
                >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                >> >> Book I am reading says that Cstr() is best method for efficency and
                >> >> safety
                >> >> however it doesnt compare that method of the .ToString() method.
                >> >>
                >> >> Which is best.
                >> >>
                >> >> Thanks
                >> >>
                >> >>
                >> >
                >> >[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • Stephany Young

                  #9
                  Re: CStr() vs. .ToString()

                  Give that man a Kewpie doll!


                  "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                  news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...[color=blue][color=green][color=darkred]
                  >>> You can't use the OO methods on a string that is "Nothing"[/color][/color]
                  >
                  > Why would you want to?
                  >
                  > Oh, I get it, you're too lazy to check the data before performing an
                  > operation it. Isn't checking your data a 100 level concept?
                  >
                  > I'm guessing that On Error Resume Next is one of your friends too.
                  >
                  > Bob Lehmann
                  >
                  > "CMM" <cmm@nospam.com > wrote in message
                  > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...[color=green]
                  >> I don't think that's true at all. First off, CStr,CBool, Etc. are all
                  >> just
                  >> easier-to-read specialized wrappers around CType..... which in and of[/color]
                  > itself[color=green]
                  >> is a special "VB" construct. The true "non-VB" casting operator is
                  >> DirectCast(...) .
                  >>
                  >> Contrary to what Scott M says you're SUPPOSED to use them. What's the[/color]
                  > point[color=green]
                  >> of using VB if you're not going to use its special methods that make your
                  >> life easier? This is straight from the VB documentation:
                  >>
                  >> "As a rule, you should use the Visual Basic type conversion functions in
                  >> preference to the .NET Framework methods such as ToString(), either on
                  >> the
                  >> Convert class or on an individual type structure or class. The Visual[/color]
                  > Basic[color=green]
                  >> functions are designed for optimal interaction with Visual Basic code,
                  >> and
                  >> they also make your source code shorter and easier to read. In addition,[/color]
                  > the[color=green]
                  >> .NET Framework conversion methods do not always produce the same results[/color]
                  > as[color=green]
                  >> the Visual Basic functions, for example when converting Boolean to[/color]
                  > Integer.[color=green]
                  >> For more information, see Troubleshooting Data Types."
                  >>
                  >> In addition, although I'm a guy who always initializes strings and
                  >> objects
                  >> as soon as possible rather than have them sit around until my algorithm[/color]
                  > uses[color=green]
                  >> them- so I don't really care about the following- but, there's an[/color]
                  > advantage[color=green]
                  >> to using VB's functions: they interpret "Nothing." You can't use the OO
                  >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                  >> work).
                  >>
                  >> --
                  >> -C. Moya
                  >> www.cmoya.com
                  >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                  >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...[color=darkred]
                  >> > IMHO (and this has been debated for quite some time now), you should[/color][/color]
                  > view[color=green][color=darkred]
                  >> > all of the old "data-type" specific functions as legacy functions and
                  >> > no
                  >> > longer use them. Instead, use the more object-oriented methods of a[/color][/color]
                  > type.[color=green][color=darkred]
                  >> >
                  >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                  >> > .ToString
                  >> > All date/time functions would be replaced with methods and properties
                  >> > of
                  >> > the Date class
                  >> > All string functions would be replaced with methods and properties of[/color][/color]
                  > the[color=green][color=darkred]
                  >> > String class.
                  >> >
                  >> > et all.
                  >> >
                  >> >
                  >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                  >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                  >> >> Book I am reading says that Cstr() is best method for efficency and
                  >> >> safety
                  >> >> however it doesnt compare that method of the .ToString() method.
                  >> >>
                  >> >> Which is best.
                  >> >>
                  >> >> Thanks
                  >> >>
                  >> >>
                  >> >
                  >> >[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Bob Lehmann

                    #10
                    Re: CStr() vs. .ToString()

                    >> Checking if a variable actually contains data before doing a convert ..
                    is simply too much code.
                    You aren't serious, are you?
                    [color=blue][color=green]
                    >> If you can avoid that it makes the code a lot better readable.[/color][/color]
                    You mean like the sentence above? I'm sure you meant "a lot more better
                    readablest".

                    Happy coding, pal.

                    Bob Lehmann

                    "Martin" <x@y.com> wrote in message
                    news:uuTEZGONGH A.1536@TK2MSFTN GP11.phx.gbl...[color=blue]
                    > Wow, what happened to put you in this mood?
                    > Checking if a variable actually contains data before doing a convert to
                    > upper case is simply too much code. If you can avoid that it makes the[/color]
                    code[color=blue]
                    > a lot better readable.
                    >
                    >
                    > "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                    > news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...[color=green][color=darkred]
                    > >>> You can't use the OO methods on a string that is "Nothing"[/color]
                    > >
                    > > Why would you want to?
                    > >
                    > > Oh, I get it, you're too lazy to check the data before performing an
                    > > operation it. Isn't checking your data a 100 level concept?
                    > >
                    > > I'm guessing that On Error Resume Next is one of your friends too.
                    > >
                    > > Bob Lehmann
                    > >
                    > > "CMM" <cmm@nospam.com > wrote in message
                    > > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...[color=darkred]
                    > >> I don't think that's true at all. First off, CStr,CBool, Etc. are all
                    > >> just
                    > >> easier-to-read specialized wrappers around CType..... which in and of[/color]
                    > > itself[color=darkred]
                    > >> is a special "VB" construct. The true "non-VB" casting operator is
                    > >> DirectCast(...) .
                    > >>
                    > >> Contrary to what Scott M says you're SUPPOSED to use them. What's the[/color]
                    > > point[color=darkred]
                    > >> of using VB if you're not going to use its special methods that make[/color][/color][/color]
                    your[color=blue][color=green][color=darkred]
                    > >> life easier? This is straight from the VB documentation:
                    > >>
                    > >> "As a rule, you should use the Visual Basic type conversion functions[/color][/color][/color]
                    in[color=blue][color=green][color=darkred]
                    > >> preference to the .NET Framework methods such as ToString(), either on
                    > >> the
                    > >> Convert class or on an individual type structure or class. The Visual[/color]
                    > > Basic[color=darkred]
                    > >> functions are designed for optimal interaction with Visual Basic code,
                    > >> and
                    > >> they also make your source code shorter and easier to read. In[/color][/color][/color]
                    addition,[color=blue][color=green]
                    > > the[color=darkred]
                    > >> .NET Framework conversion methods do not always produce the same[/color][/color][/color]
                    results[color=blue][color=green]
                    > > as[color=darkred]
                    > >> the Visual Basic functions, for example when converting Boolean to[/color]
                    > > Integer.[color=darkred]
                    > >> For more information, see Troubleshooting Data Types."
                    > >>
                    > >> In addition, although I'm a guy who always initializes strings and
                    > >> objects
                    > >> as soon as possible rather than have them sit around until my algorithm[/color]
                    > > uses[color=darkred]
                    > >> them- so I don't really care about the following- but, there's an[/color]
                    > > advantage[color=darkred]
                    > >> to using VB's functions: they interpret "Nothing." You can't use the OO
                    > >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                    > >> work).
                    > >>
                    > >> --
                    > >> -C. Moya
                    > >> www.cmoya.com
                    > >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                    > >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...
                    > >> > IMHO (and this has been debated for quite some time now), you should[/color]
                    > > view[color=darkred]
                    > >> > all of the old "data-type" specific functions as legacy functions and
                    > >> > no
                    > >> > longer use them. Instead, use the more object-oriented methods of a[/color]
                    > > type.[color=darkred]
                    > >> >
                    > >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                    > >> > .ToString
                    > >> > All date/time functions would be replaced with methods and properties
                    > >> > of
                    > >> > the Date class
                    > >> > All string functions would be replaced with methods and properties of[/color]
                    > > the[color=darkred]
                    > >> > String class.
                    > >> >
                    > >> > et all.
                    > >> >
                    > >> >
                    > >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                    > >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                    > >> >> Book I am reading says that Cstr() is best method for efficency and
                    > >> >> safety
                    > >> >> however it doesnt compare that method of the .ToString() method.
                    > >> >>
                    > >> >> Which is best.
                    > >> >>
                    > >> >> Thanks
                    > >> >>
                    > >> >>
                    > >> >
                    > >> >
                    > >>
                    > >>[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Martin

                      #11
                      Re: CStr() vs. .ToString()

                      Just wondering... Have you ever contibuted anything positive to this
                      newsgroup? (or to anything else)


                      "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                      news:e6ugG1ONGH A.3944@tk2msftn gp13.phx.gbl...[color=blue][color=green][color=darkred]
                      >>> Checking if a variable actually contains data before doing a convert ..[/color][/color]
                      > is simply too much code.
                      > You aren't serious, are you?
                      >[color=green][color=darkred]
                      >>> If you can avoid that it makes the code a lot better readable.[/color][/color]
                      > You mean like the sentence above? I'm sure you meant "a lot more better
                      > readablest".
                      >
                      > Happy coding, pal.
                      >
                      > Bob Lehmann
                      >
                      > "Martin" <x@y.com> wrote in message
                      > news:uuTEZGONGH A.1536@TK2MSFTN GP11.phx.gbl...[color=green]
                      >> Wow, what happened to put you in this mood?
                      >> Checking if a variable actually contains data before doing a convert to
                      >> upper case is simply too much code. If you can avoid that it makes the[/color]
                      > code[color=green]
                      >> a lot better readable.
                      >>
                      >>
                      >> "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                      >> news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...[color=darkred]
                      >> >>> You can't use the OO methods on a string that is "Nothing"
                      >> >
                      >> > Why would you want to?
                      >> >
                      >> > Oh, I get it, you're too lazy to check the data before performing an
                      >> > operation it. Isn't checking your data a 100 level concept?
                      >> >
                      >> > I'm guessing that On Error Resume Next is one of your friends too.
                      >> >
                      >> > Bob Lehmann
                      >> >
                      >> > "CMM" <cmm@nospam.com > wrote in message
                      >> > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...
                      >> >> I don't think that's true at all. First off, CStr,CBool, Etc. are all
                      >> >> just
                      >> >> easier-to-read specialized wrappers around CType..... which in and of
                      >> > itself
                      >> >> is a special "VB" construct. The true "non-VB" casting operator is
                      >> >> DirectCast(...) .
                      >> >>
                      >> >> Contrary to what Scott M says you're SUPPOSED to use them. What's the
                      >> > point
                      >> >> of using VB if you're not going to use its special methods that make[/color][/color]
                      > your[color=green][color=darkred]
                      >> >> life easier? This is straight from the VB documentation:
                      >> >>
                      >> >> "As a rule, you should use the Visual Basic type conversion functions[/color][/color]
                      > in[color=green][color=darkred]
                      >> >> preference to the .NET Framework methods such as ToString(), either on
                      >> >> the
                      >> >> Convert class or on an individual type structure or class. The Visual
                      >> > Basic
                      >> >> functions are designed for optimal interaction with Visual Basic code,
                      >> >> and
                      >> >> they also make your source code shorter and easier to read. In[/color][/color]
                      > addition,[color=green][color=darkred]
                      >> > the
                      >> >> .NET Framework conversion methods do not always produce the same[/color][/color]
                      > results[color=green][color=darkred]
                      >> > as
                      >> >> the Visual Basic functions, for example when converting Boolean to
                      >> > Integer.
                      >> >> For more information, see Troubleshooting Data Types."
                      >> >>
                      >> >> In addition, although I'm a guy who always initializes strings and
                      >> >> objects
                      >> >> as soon as possible rather than have them sit around until my
                      >> >> algorithm
                      >> > uses
                      >> >> them- so I don't really care about the following- but, there's an
                      >> > advantage
                      >> >> to using VB's functions: they interpret "Nothing." You can't use the
                      >> >> OO
                      >> >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                      >> >> work).
                      >> >>
                      >> >> --
                      >> >> -C. Moya
                      >> >> www.cmoya.com
                      >> >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                      >> >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...
                      >> >> > IMHO (and this has been debated for quite some time now), you should
                      >> > view
                      >> >> > all of the old "data-type" specific functions as legacy functions
                      >> >> > and
                      >> >> > no
                      >> >> > longer use them. Instead, use the more object-oriented methods of a
                      >> > type.
                      >> >> >
                      >> >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                      >> >> > .ToString
                      >> >> > All date/time functions would be replaced with methods and
                      >> >> > properties
                      >> >> > of
                      >> >> > the Date class
                      >> >> > All string functions would be replaced with methods and properties
                      >> >> > of
                      >> > the
                      >> >> > String class.
                      >> >> >
                      >> >> > et all.
                      >> >> >
                      >> >> >
                      >> >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                      >> >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                      >> >> >> Book I am reading says that Cstr() is best method for efficency and
                      >> >> >> safety
                      >> >> >> however it doesnt compare that method of the .ToString() method.
                      >> >> >>
                      >> >> >> Which is best.
                      >> >> >>
                      >> >> >> Thanks
                      >> >> >>
                      >> >> >>
                      >> >> >
                      >> >> >
                      >> >>
                      >> >>
                      >> >
                      >> >[/color]
                      >>
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      • CMM

                        #12
                        Re: CStr() vs. .ToString()

                        Nonsense. CStr is not some VB6 (better term is VB.Classic) legacy thing....
                        in .NET it's just a convenience wrapper around CType... which when used to
                        cast to a string is simply a wrapper around the object's ToString("G"). I
                        personally tend to use ToString() as well on my own strings.... but when I'm
                        handling strings that come from functions that I know might return nulls I'd
                        tend to use CStr().... it's the same exact thing as typing out all your "If
                        bla Is Nothing" code that I'm sure litters your nasty code (or maybe it
                        doesn't.... which is just as bad).

                        P.S. I'm not sure you know what a Method vs. a Function vs. a Statement
                        is... at least judging from the poppycock vomited in your post.

                        --
                        -C. Moya

                        "Scott M." <s-mar@nospam.nosp am> wrote in message
                        news:eBEJ1bNNGH A.2816@TK2MSFTN GP15.phx.gbl...[color=blue]
                        >
                        > "guy" <guy@discussion s.microsoft.com > wrote in message
                        > news:2199BA10-0B41-4D7D-B7AF-F34D469457BD@mi crosoft.com...[color=green]
                        >> both points of view are valid, however i use the vb string methods as the
                        >> compiler makes optimzations that can improve performance over the native
                        >> .Net
                        >> methods, also i find the vb methods read better.[/color]
                        >
                        > The VB 6.0 way are not methods, they are functions. The .NET way are
                        > object methods. The VB.NET compiler does NOT optimize the VB 6.0
                        > functions to work BETTER than the natvie .NET object methods.
                        >
                        > To answer your question, ToString would be my suggestion, rather than
                        > CStr(). ToString is a method of the Object Type, and since all classes
                        > inherit from Object, all objects have this method.
                        >
                        >[color=green]
                        >>
                        >> cheers
                        >>
                        >> guy
                        >>
                        >> "Scott M." wrote:
                        >>[color=darkred]
                        >>> IMHO (and this has been debated for quite some time now), you should
                        >>> view
                        >>> all of the old "data-type" specific functions as legacy functions and no
                        >>> longer use them. Instead, use the more object-oriented methods of a
                        >>> type.
                        >>>
                        >>> CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                        >>> .ToString
                        >>> All date/time functions would be replaced with methods and properties of
                        >>> the
                        >>> Date class
                        >>> All string functions would be replaced with methods and properties of
                        >>> the
                        >>> String class.
                        >>>
                        >>> et all.
                        >>>
                        >>>
                        >>> "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                        >>> news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                        >>> > Book I am reading says that Cstr() is best method for efficency and
                        >>> > safety
                        >>> > however it doesnt compare that method of the .ToString() method.
                        >>> >
                        >>> > Which is best.
                        >>> >
                        >>> > Thanks
                        >>> >
                        >>> >
                        >>>
                        >>>
                        >>>[/color][/color]
                        >
                        >[/color]


                        Comment

                        • Bob Lehmann

                          #13
                          Re: CStr() vs. .ToString()

                          >> Have you ever contibuted anything positive
                          Uh, yeah.

                          I suggested that checking your data before performing operations the data is
                          a best practice. I highly doubt that any competent programmer would
                          disagree. Apparently you are not in that group.

                          Or, is your specialty in buffer overruns?

                          At least you have a sound rationale -
                          "Checking if a variable actually contains data before doing a convert to
                          upper case is simply too much code."

                          Waaaaa! But Mom, those extra 20 keystrokes to check the data are soooo hard
                          to do. And besides, my code is better readable since you know I don't indent
                          If blocks.

                          Perhaps you should stick to scripting languages where you don't have all the
                          icky typed variable stuff going on. I mean, isn't it a hassle declaring all
                          those variable thingys, with all that code and stuff?

                          Maybe, after you've completed Junior High, you'll have a different
                          perspective.
                          [color=blue][color=green]
                          >> (or to anything else)[/color][/color]
                          Yes, I don't write malware.

                          Bob Lehmann

                          "Martin" <x@y.com> wrote in message
                          news:eFF6lBPNGH A.536@TK2MSFTNG P09.phx.gbl...[color=blue]
                          > Just wondering... Have you ever contibuted anything positive to this
                          > newsgroup? (or to anything else)
                          >
                          >
                          > "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                          > news:e6ugG1ONGH A.3944@tk2msftn gp13.phx.gbl...[color=green][color=darkred]
                          > >>> Checking if a variable actually contains data before doing a convert[/color][/color][/color]
                          ...[color=blue][color=green]
                          > > is simply too much code.
                          > > You aren't serious, are you?
                          > >[color=darkred]
                          > >>> If you can avoid that it makes the code a lot better readable.[/color]
                          > > You mean like the sentence above? I'm sure you meant "a lot more better
                          > > readablest".
                          > >
                          > > Happy coding, pal.
                          > >
                          > > Bob Lehmann
                          > >
                          > > "Martin" <x@y.com> wrote in message
                          > > news:uuTEZGONGH A.1536@TK2MSFTN GP11.phx.gbl...[color=darkred]
                          > >> Wow, what happened to put you in this mood?
                          > >> Checking if a variable actually contains data before doing a convert to
                          > >> upper case is simply too much code. If you can avoid that it makes the[/color]
                          > > code[color=darkred]
                          > >> a lot better readable.
                          > >>
                          > >>
                          > >> "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                          > >> news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...
                          > >> >>> You can't use the OO methods on a string that is "Nothing"
                          > >> >
                          > >> > Why would you want to?
                          > >> >
                          > >> > Oh, I get it, you're too lazy to check the data before performing an
                          > >> > operation it. Isn't checking your data a 100 level concept?
                          > >> >
                          > >> > I'm guessing that On Error Resume Next is one of your friends too.
                          > >> >
                          > >> > Bob Lehmann
                          > >> >
                          > >> > "CMM" <cmm@nospam.com > wrote in message
                          > >> > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...
                          > >> >> I don't think that's true at all. First off, CStr,CBool, Etc. are[/color][/color][/color]
                          all[color=blue][color=green][color=darkred]
                          > >> >> just
                          > >> >> easier-to-read specialized wrappers around CType..... which in and[/color][/color][/color]
                          of[color=blue][color=green][color=darkred]
                          > >> > itself
                          > >> >> is a special "VB" construct. The true "non-VB" casting operator is
                          > >> >> DirectCast(...) .
                          > >> >>
                          > >> >> Contrary to what Scott M says you're SUPPOSED to use them. What's[/color][/color][/color]
                          the[color=blue][color=green][color=darkred]
                          > >> > point
                          > >> >> of using VB if you're not going to use its special methods that make[/color]
                          > > your[color=darkred]
                          > >> >> life easier? This is straight from the VB documentation:
                          > >> >>
                          > >> >> "As a rule, you should use the Visual Basic type conversion[/color][/color][/color]
                          functions[color=blue][color=green]
                          > > in[color=darkred]
                          > >> >> preference to the .NET Framework methods such as ToString(), either[/color][/color][/color]
                          on[color=blue][color=green][color=darkred]
                          > >> >> the
                          > >> >> Convert class or on an individual type structure or class. The[/color][/color][/color]
                          Visual[color=blue][color=green][color=darkred]
                          > >> > Basic
                          > >> >> functions are designed for optimal interaction with Visual Basic[/color][/color][/color]
                          code,[color=blue][color=green][color=darkred]
                          > >> >> and
                          > >> >> they also make your source code shorter and easier to read. In[/color]
                          > > addition,[color=darkred]
                          > >> > the
                          > >> >> .NET Framework conversion methods do not always produce the same[/color]
                          > > results[color=darkred]
                          > >> > as
                          > >> >> the Visual Basic functions, for example when converting Boolean to
                          > >> > Integer.
                          > >> >> For more information, see Troubleshooting Data Types."
                          > >> >>
                          > >> >> In addition, although I'm a guy who always initializes strings and
                          > >> >> objects
                          > >> >> as soon as possible rather than have them sit around until my
                          > >> >> algorithm
                          > >> > uses
                          > >> >> them- so I don't really care about the following- but, there's an
                          > >> > advantage
                          > >> >> to using VB's functions: they interpret "Nothing." You can't use the
                          > >> >> OO
                          > >> >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                          > >> >> work).
                          > >> >>
                          > >> >> --
                          > >> >> -C. Moya
                          > >> >> www.cmoya.com
                          > >> >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                          > >> >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...
                          > >> >> > IMHO (and this has been debated for quite some time now), you[/color][/color][/color]
                          should[color=blue][color=green][color=darkred]
                          > >> > view
                          > >> >> > all of the old "data-type" specific functions as legacy functions
                          > >> >> > and
                          > >> >> > no
                          > >> >> > longer use them. Instead, use the more object-oriented methods of[/color][/color][/color]
                          a[color=blue][color=green][color=darkred]
                          > >> > type.
                          > >> >> >
                          > >> >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                          > >> >> > .ToString
                          > >> >> > All date/time functions would be replaced with methods and
                          > >> >> > properties
                          > >> >> > of
                          > >> >> > the Date class
                          > >> >> > All string functions would be replaced with methods and properties
                          > >> >> > of
                          > >> > the
                          > >> >> > String class.
                          > >> >> >
                          > >> >> > et all.
                          > >> >> >
                          > >> >> >
                          > >> >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                          > >> >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                          > >> >> >> Book I am reading says that Cstr() is best method for efficency[/color][/color][/color]
                          and[color=blue][color=green][color=darkred]
                          > >> >> >> safety
                          > >> >> >> however it doesnt compare that method of the .ToString() method.
                          > >> >> >>
                          > >> >> >> Which is best.
                          > >> >> >>
                          > >> >> >> Thanks
                          > >> >> >>
                          > >> >> >>
                          > >> >> >
                          > >> >> >
                          > >> >>
                          > >> >>
                          > >> >
                          > >> >
                          > >>
                          > >>[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Martin

                            #14
                            Re: CStr() vs. .ToString()

                            Finishing junior high may be your problem. I have a real education ;-)

                            "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                            news:ubhnniPNGH A.3276@TK2MSFTN GP09.phx.gbl...[color=blue][color=green][color=darkred]
                            >>> Have you ever contibuted anything positive[/color][/color]
                            > Uh, yeah.
                            >
                            > I suggested that checking your data before performing operations the data
                            > is
                            > a best practice. I highly doubt that any competent programmer would
                            > disagree. Apparently you are not in that group.
                            >
                            > Or, is your specialty in buffer overruns?
                            >
                            > At least you have a sound rationale -
                            > "Checking if a variable actually contains data before doing a convert to
                            > upper case is simply too much code."
                            >
                            > Waaaaa! But Mom, those extra 20 keystrokes to check the data are soooo
                            > hard
                            > to do. And besides, my code is better readable since you know I don't
                            > indent
                            > If blocks.
                            >
                            > Perhaps you should stick to scripting languages where you don't have all
                            > the
                            > icky typed variable stuff going on. I mean, isn't it a hassle declaring
                            > all
                            > those variable thingys, with all that code and stuff?
                            >
                            > Maybe, after you've completed Junior High, you'll have a different
                            > perspective.
                            >[color=green][color=darkred]
                            >>> (or to anything else)[/color][/color]
                            > Yes, I don't write malware.
                            >
                            > Bob Lehmann
                            >
                            > "Martin" <x@y.com> wrote in message
                            > news:eFF6lBPNGH A.536@TK2MSFTNG P09.phx.gbl...[color=green]
                            >> Just wondering... Have you ever contibuted anything positive to this
                            >> newsgroup? (or to anything else)
                            >>
                            >>
                            >> "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                            >> news:e6ugG1ONGH A.3944@tk2msftn gp13.phx.gbl...[color=darkred]
                            >> >>> Checking if a variable actually contains data before doing a convert[/color][/color]
                            > ..[color=green][color=darkred]
                            >> > is simply too much code.
                            >> > You aren't serious, are you?
                            >> >
                            >> >>> If you can avoid that it makes the code a lot better readable.
                            >> > You mean like the sentence above? I'm sure you meant "a lot more better
                            >> > readablest".
                            >> >
                            >> > Happy coding, pal.
                            >> >
                            >> > Bob Lehmann
                            >> >
                            >> > "Martin" <x@y.com> wrote in message
                            >> > news:uuTEZGONGH A.1536@TK2MSFTN GP11.phx.gbl...
                            >> >> Wow, what happened to put you in this mood?
                            >> >> Checking if a variable actually contains data before doing a convert
                            >> >> to
                            >> >> upper case is simply too much code. If you can avoid that it makes the
                            >> > code
                            >> >> a lot better readable.
                            >> >>
                            >> >>
                            >> >> "Bob Lehmann" <nospam@dontbot herme.zzz> wrote in message
                            >> >> news:epp0n5NNGH A.3856@TK2MSFTN GP12.phx.gbl...
                            >> >> >>> You can't use the OO methods on a string that is "Nothing"
                            >> >> >
                            >> >> > Why would you want to?
                            >> >> >
                            >> >> > Oh, I get it, you're too lazy to check the data before performing an
                            >> >> > operation it. Isn't checking your data a 100 level concept?
                            >> >> >
                            >> >> > I'm guessing that On Error Resume Next is one of your friends too.
                            >> >> >
                            >> >> > Bob Lehmann
                            >> >> >
                            >> >> > "CMM" <cmm@nospam.com > wrote in message
                            >> >> > news:%23h%23gze NNGHA.1676@TK2M SFTNGP09.phx.gb l...
                            >> >> >> I don't think that's true at all. First off, CStr,CBool, Etc. are[/color][/color]
                            > all[color=green][color=darkred]
                            >> >> >> just
                            >> >> >> easier-to-read specialized wrappers around CType..... which in and[/color][/color]
                            > of[color=green][color=darkred]
                            >> >> > itself
                            >> >> >> is a special "VB" construct. The true "non-VB" casting operator is
                            >> >> >> DirectCast(...) .
                            >> >> >>
                            >> >> >> Contrary to what Scott M says you're SUPPOSED to use them. What's[/color][/color]
                            > the[color=green][color=darkred]
                            >> >> > point
                            >> >> >> of using VB if you're not going to use its special methods that
                            >> >> >> make
                            >> > your
                            >> >> >> life easier? This is straight from the VB documentation:
                            >> >> >>
                            >> >> >> "As a rule, you should use the Visual Basic type conversion[/color][/color]
                            > functions[color=green][color=darkred]
                            >> > in
                            >> >> >> preference to the .NET Framework methods such as ToString(), either[/color][/color]
                            > on[color=green][color=darkred]
                            >> >> >> the
                            >> >> >> Convert class or on an individual type structure or class. The[/color][/color]
                            > Visual[color=green][color=darkred]
                            >> >> > Basic
                            >> >> >> functions are designed for optimal interaction with Visual Basic[/color][/color]
                            > code,[color=green][color=darkred]
                            >> >> >> and
                            >> >> >> they also make your source code shorter and easier to read. In
                            >> > addition,
                            >> >> > the
                            >> >> >> .NET Framework conversion methods do not always produce the same
                            >> > results
                            >> >> > as
                            >> >> >> the Visual Basic functions, for example when converting Boolean to
                            >> >> > Integer.
                            >> >> >> For more information, see Troubleshooting Data Types."
                            >> >> >>
                            >> >> >> In addition, although I'm a guy who always initializes strings and
                            >> >> >> objects
                            >> >> >> as soon as possible rather than have them sit around until my
                            >> >> >> algorithm
                            >> >> > uses
                            >> >> >> them- so I don't really care about the following- but, there's an
                            >> >> > advantage
                            >> >> >> to using VB's functions: they interpret "Nothing." You can't use
                            >> >> >> the
                            >> >> >> OO
                            >> >> >> methods on a string that is "Nothing" (s.ToUpper for instance won't
                            >> >> >> work).
                            >> >> >>
                            >> >> >> --
                            >> >> >> -C. Moya
                            >> >> >> www.cmoya.com
                            >> >> >> "Scott M." <s-mar@nospam.nosp am> wrote in message
                            >> >> >> news:O7e3xHLNGH A.2036@TK2MSFTN GP14.phx.gbl...
                            >> >> >> > IMHO (and this has been debated for quite some time now), you[/color][/color]
                            > should[color=green][color=darkred]
                            >> >> > view
                            >> >> >> > all of the old "data-type" specific functions as legacy functions
                            >> >> >> > and
                            >> >> >> > no
                            >> >> >> > longer use them. Instead, use the more object-oriented methods
                            >> >> >> > of[/color][/color]
                            > a[color=green][color=darkred]
                            >> >> > type.
                            >> >> >> >
                            >> >> >> > CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                            >> >> >> > .ToString
                            >> >> >> > All date/time functions would be replaced with methods and
                            >> >> >> > properties
                            >> >> >> > of
                            >> >> >> > the Date class
                            >> >> >> > All string functions would be replaced with methods and
                            >> >> >> > properties
                            >> >> >> > of
                            >> >> > the
                            >> >> >> > String class.
                            >> >> >> >
                            >> >> >> > et all.
                            >> >> >> >
                            >> >> >> >
                            >> >> >> > "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                            >> >> >> > news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                            >> >> >> >> Book I am reading says that Cstr() is best method for efficency[/color][/color]
                            > and[color=green][color=darkred]
                            >> >> >> >> safety
                            >> >> >> >> however it doesnt compare that method of the .ToString() method.
                            >> >> >> >>
                            >> >> >> >> Which is best.
                            >> >> >> >>
                            >> >> >> >> Thanks
                            >> >> >> >>
                            >> >> >> >>
                            >> >> >> >
                            >> >> >> >
                            >> >> >>
                            >> >> >>
                            >> >> >
                            >> >> >
                            >> >>
                            >> >>
                            >> >
                            >> >[/color]
                            >>
                            >>[/color]
                            >
                            >[/color]


                            Comment

                            • Scott M.

                              #15
                              Re: CStr() vs. .ToString()

                              I think you better read your own post. CStr() is a built-in function of the
                              VB 6 language. It is not a method. ToString is a method of the Object type
                              (which all classes in .NET derive from). So, I'm not sure why you feel the
                              need to call this poppycock and suggest that I don't know what a function
                              vs. a method is.

                              As for which is better... As I said in my first post, it is a matter of
                              choice and I prefer the more object-oriented ToString object method.


                              "CMM" <cmm@nospam.com > wrote in message
                              news:edKgVRPNGH A.1608@TK2MSFTN GP11.phx.gbl...[color=blue]
                              > Nonsense. CStr is not some VB6 (better term is VB.Classic) legacy
                              > thing.... in .NET it's just a convenience wrapper around CType... which
                              > when used to cast to a string is simply a wrapper around the object's
                              > ToString("G"). I personally tend to use ToString() as well on my own
                              > strings.... but when I'm handling strings that come from functions that I
                              > know might return nulls I'd tend to use CStr().... it's the same exact
                              > thing as typing out all your "If bla Is Nothing" code that I'm sure
                              > litters your nasty code (or maybe it doesn't.... which is just as bad).
                              >
                              > P.S. I'm not sure you know what a Method vs. a Function vs. a Statement
                              > is... at least judging from the poppycock vomited in your post.
                              >
                              > --
                              > -C. Moya
                              > www.cmoya.com
                              > "Scott M." <s-mar@nospam.nosp am> wrote in message
                              > news:eBEJ1bNNGH A.2816@TK2MSFTN GP15.phx.gbl...[color=green]
                              >>
                              >> "guy" <guy@discussion s.microsoft.com > wrote in message
                              >> news:2199BA10-0B41-4D7D-B7AF-F34D469457BD@mi crosoft.com...[color=darkred]
                              >>> both points of view are valid, however i use the vb string methods as
                              >>> the
                              >>> compiler makes optimzations that can improve performance over the native
                              >>> .Net
                              >>> methods, also i find the vb methods read better.[/color]
                              >>
                              >> The VB 6.0 way are not methods, they are functions. The .NET way are
                              >> object methods. The VB.NET compiler does NOT optimize the VB 6.0
                              >> functions to work BETTER than the natvie .NET object methods.
                              >>
                              >> To answer your question, ToString would be my suggestion, rather than
                              >> CStr(). ToString is a method of the Object Type, and since all classes
                              >> inherit from Object, all objects have this method.
                              >>
                              >>[color=darkred]
                              >>>
                              >>> cheers
                              >>>
                              >>> guy
                              >>>
                              >>> "Scott M." wrote:
                              >>>
                              >>>> IMHO (and this has been debated for quite some time now), you should
                              >>>> view
                              >>>> all of the old "data-type" specific functions as legacy functions and
                              >>>> no
                              >>>> longer use them. Instead, use the more object-oriented methods of a
                              >>>> type.
                              >>>>
                              >>>> CStr, CBool, CDbl, CInt, etc. would all be replaced with CType or
                              >>>> .ToString
                              >>>> All date/time functions would be replaced with methods and properties
                              >>>> of the
                              >>>> Date class
                              >>>> All string functions would be replaced with methods and properties of
                              >>>> the
                              >>>> String class.
                              >>>>
                              >>>> et all.
                              >>>>
                              >>>>
                              >>>> "Sean" <Sean@discussio ns.microsoft.co m> wrote in message
                              >>>> news:68FBFD12-1AF2-4F12-821F-2CC4E6F8E957@mi crosoft.com...
                              >>>> > Book I am reading says that Cstr() is best method for efficency and
                              >>>> > safety
                              >>>> > however it doesnt compare that method of the .ToString() method.
                              >>>> >
                              >>>> > Which is best.
                              >>>> >
                              >>>> > Thanks
                              >>>> >
                              >>>> >
                              >>>>
                              >>>>
                              >>>>[/color]
                              >>
                              >>[/color]
                              >
                              >[/color]


                              Comment

                              Working...