Format$ question

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

    #1

    Format$ question

    Dim x As String
    x = Format$("50", "00000000")

    in vb6 x returns "00000050"

    in vb.net 2005 x returns "0000000"

    How do I get the vb6 result in vb.net 2005?




  • zacks@construction-imaging.com

    #2
    Re: Format$ question

    On Sep 13, 1:25 pm, "phhonl" <phh...@newsgro ups.nospamwrote :
    Dim x As String
    x = Format$("50", "00000000")
    >
    in vb6 x returns "00000050"
    >
    in vb.net 2005 x returns "0000000"
    >
    How do I get the vb6 result in vb.net 2005?
    How are you doing it in .NET, with the Format function or the
    string.Format method?

    Comment

    • phhonl

      #3
      Re: Format$ question

      In .net I tried:

      x = System.String.F ormat("50", "00000000")

      and that returns "50". I need it to return "00000050"


      <zacks@construc tion-imaging.comwrot e in message
      news:1189705377 .998475.236520@ k79g2000hse.goo glegroups.com.. .
      On Sep 13, 1:25 pm, "phhonl" <phh...@newsgro ups.nospamwrote :
      >Dim x As String
      >x = Format$("50", "00000000")
      >>
      >in vb6 x returns "00000050"
      >>
      >in vb.net 2005 x returns "0000000"
      >>
      >How do I get the vb6 result in vb.net 2005?
      >
      How are you doing it in .NET, with the Format function or the
      string.Format method?
      >

      Comment

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

        #4
        Re: Format$ question

        phhonl wrote:
        In .net I tried:
        >
        x = System.String.F ormat("50", "00000000")
        >
        and that returns "50". I need it to return "00000050"
        >
        The Format.String method doesn't work like the Format$ function. The
        format comes first, and the format string has to contain format
        specifiers as it can format several values:

        x = String.Format(" {0:00000000}", 50)

        You can use the ToString method to format a single value:

        x = 50.ToString("00 000000")

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

        Comment

        • phhonl

          #5
          Re: Format$ question

          Thanks to you and Armin for the help. I appreciate it.


          "Göran Andersson" <guffa@guffa.co mwrote in message
          news:uiJSomj9HH A.5404@TK2MSFTN GP02.phx.gbl...
          phhonl wrote:
          >In .net I tried:
          >>
          >x = System.String.F ormat("50", "00000000")
          >>
          >and that returns "50". I need it to return "00000050"
          >>
          >
          The Format.String method doesn't work like the Format$ function. The
          format comes first, and the format string has to contain format specifiers
          as it can format several values:
          >
          x = String.Format(" {0:00000000}", 50)
          >
          You can use the ToString method to format a single value:
          >
          x = 50.ToString("00 000000")
          >
          --
          Göran Andersson
          _____
          http://www.guffa.com

          Comment

          • Phill W.

            #6
            Re: Format$ question

            phhonl wrote:
            Dim x As String
            x = Format$("50", "00000000")
            in vb6 x returns "00000050"
            in vb.net 2005 x returns "0000000"
            How do I get the vb6 result in vb.net 2005?
            Use the correct Data Types.

            "50" is a String and can only be formatted using the /string/ formatting
            characters ("@" being the only one, IIRC).

            50 is an Integer and can use all the /numeric/ formatting characters, as
            you would expect.

            x = Format(50, "00000000")

            or, better still,

            x = 50.ToString("00 000000")

            VB "Proper" used its Evil Type Coercion to translate the String value
            into an integer value for you.

            Visual Basic - the shiny new, all grown-up, object-oriented language -
            /doesn't/.

            HTH,
            Phill W.

            Comment

            Working...