Format() method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?S2FubmFu?=

    #1

    Format() method

    hi,

    I would like to add $ symbol in numeric amount. For that I have used
    Microsoft.Visua lBasic.Strings. Format(strAmoun t, "$0.00").

    But it seems to me that I am using VisualBasic name space and my manager
    wants to use .Net name space function instead of VisualBasic. Is there is any
    function availble for this in .Net?

    Sorry I am new to .Net hence I am not sure about this.

    Regards,
    Ramesh
  • Spam Catcher

    #2
    Re: Format() method

    =?Utf-8?B?S2FubmFu?= <Kannan@discuss ions.microsoft. comwrote in
    news:C3747567-15F8-48D6-8A79-5DFC05F91D18@mi crosoft.com:
    But it seems to me that I am using VisualBasic name space and my
    manager wants to use .Net name space function instead of VisualBasic.
    Is there is any function availble for this in .Net?
    String.Format.

    Comment

    • Al Reid

      #3
      Re: Format() method

      "Kannan" <Kannan@discuss ions.microsoft. comwrote in message news:C3747567-15F8-48D6-8A79-5DFC05F91D18@mi crosoft.com...
      hi,
      >
      I would like to add $ symbol in numeric amount. For that I have used
      Microsoft.Visua lBasic.Strings. Format(strAmoun t, "$0.00").
      >
      But it seems to me that I am using VisualBasic name space and my manager
      wants to use .Net name space function instead of VisualBasic. Is there is any
      function availble for this in .Net?
      >
      Sorry I am new to .Net hence I am not sure about this.
      >
      Regards,
      Ramesh
      Why does your manager let you program VB if there is an aversion to using the VisualBasic namespace? I really don't understand that
      position.


      --
      Al Reid



      Comment

      • Phill W.

        #4
        Re: Format() method

        Kannan wrote:
        I would like to add $ symbol in numeric amount. For that I have used
        Microsoft.Visua lBasic.Strings. Format(strAmoun t, "$0.00").
        >
        But it seems to me that I am using VisualBasic name space and my manager
        wants to use .Net name space function instead of VisualBasic.
        Why? Are you writing Visual Basic code or not?
        If you are, then the /compiler/ will be using stuff from
        Microsoft.Visua lBasic under the covers - you're not saving or gaining
        anything by ignoring the functionality that's provided for you.
        If you want to go down that road, write in C#.
        Is there is any function availble for this in .Net?
        Well, yes, there is but, looking at your code, you need to be careful.

        Imports VB = Microsoft.Visua lBasic

        Dim s as String _
        = VB.Strings.Form at( strAmount, "$0.00" )

        You're relying on Evil Type Coercion to convert "strAmount" from a
        String into a numeric value, before formatting it using a numeric
        formatting pattern. AFAIK, none of the .Net methods will do this;
        you'll have to do the conversion yourself, as in

        Dim d as Double _
        = CDbl( strAmount ) ' I know; I'm terrible :-)
        Dim s as String _
        = d.ToString( "$0.00" )

        HTH,
        Phill W.

        Comment

        • Smokey Grindle

          #5
          Re: Format() method

          VisualBasic namespace is really just for legacy stuff and converted
          projects... if you want to code in "true" .NET you should not use it and
          find the real way to do it from the System namespace down.. you never know
          when MS may ditch the VisualBasic namespace


          "Al Reid" <areidjr@reidDA SHhome.comwrote in message
          news:eIDPx%23qo HHA.3772@TK2MSF TNGP03.phx.gbl. ..
          "Kannan" <Kannan@discuss ions.microsoft. comwrote in message
          news:C3747567-15F8-48D6-8A79-5DFC05F91D18@mi crosoft.com...
          >hi,
          >>
          >I would like to add $ symbol in numeric amount. For that I have used
          >Microsoft.Visu alBasic.Strings .Format(strAmou nt, "$0.00").
          >>
          >But it seems to me that I am using VisualBasic name space and my manager
          >wants to use .Net name space function instead of VisualBasic. Is there is
          >any
          >function availble for this in .Net?
          >>
          >Sorry I am new to .Net hence I am not sure about this.
          >>
          >Regards,
          >Ramesh
          >
          Why does your manager let you program VB if there is an aversion to using
          the VisualBasic namespace? I really don't understand that
          position.
          >
          >
          --
          Al Reid
          >
          >
          >

          Comment

          • Al Reid

            #6
            Re: Format() method

            I believe you are quite mistaken. The VisualBasic.Com patibility namespace is there for that purpose. If you don't like VB, then
            switch to C#.

            --
            Al Reid


            "Smokey Grindle" <nospam@nospam. comwrote in message news:uCEuzpvoHH A.596@TK2MSFTNG P06.phx.gbl...
            VisualBasic namespace is really just for legacy stuff and converted
            projects... if you want to code in "true" .NET you should not use it and
            find the real way to do it from the System namespace down.. you never know
            when MS may ditch the VisualBasic namespace
            >
            >
            "Al Reid" <areidjr@reidDA SHhome.comwrote in message
            news:eIDPx%23qo HHA.3772@TK2MSF TNGP03.phx.gbl. ..
            "Kannan" <Kannan@discuss ions.microsoft. comwrote in message
            news:C3747567-15F8-48D6-8A79-5DFC05F91D18@mi crosoft.com...
            hi,
            >
            I would like to add $ symbol in numeric amount. For that I have used
            Microsoft.Visua lBasic.Strings. Format(strAmoun t, "$0.00").
            >
            But it seems to me that I am using VisualBasic name space and my manager
            wants to use .Net name space function instead of VisualBasic. Is there is
            any
            function availble for this in .Net?
            >
            Sorry I am new to .Net hence I am not sure about this.
            >
            Regards,
            Ramesh
            Why does your manager let you program VB if there is an aversion to using
            the VisualBasic namespace? I really don't understand that
            position.


            --
            Al Reid

            >
            >

            Comment

            • Phill W.

              #7
              Re: Format() method

              Smokey Grindle wrote:
              VisualBasic namespace is really just for legacy stuff and converted
              projects... if you want to code in "true" .NET you should not use it and
              find the real way to do it from the System namespace down.. you never know
              when MS may ditch the VisualBasic namespace
              I would beg to differ.

              The Microsoft.Visua lBasic./Compatibility/ assembly contains all the
              "old" stuff that we really /shouldn't/ be bothering with any more -
              fixed length strings and such like (yuk!).

              The Microsoft.Visua lBasic assembly is part and parcel of the language,
              like it or not - it's even used by the Visual Basic /compiler/, under
              the covers. Just see /if/ you can compile a V.B. assembly that
              /doesn't/ have a dependency on this assembly!

              (and, if you /haven't/ got to VB'2005 yet, just what /is/ the "true
              ..Net" version of

              ReDim Preserve myArray( 22 )

              ??

              Regards,
              Phill W.

              Comment

              Working...