Format text in label to amount

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • staeri@gmail.com

    Format text in label to amount

    I'm populating a label with an amount like this:

    lblBudget.Text = Generic_databas e_functions.Get Value("SELECT
    ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")

    I want the amount in the label to be shown as "10.000" not "10000".
    How can I format the amount?

    I'm very grateful for help!

    // S
  • Mark Rae [MVP]

    #2
    Re: Format text in label to amount

    <staeri@gmail.c omwrote in message
    news:542351c6-f9e5-4714-be00-fbc6cef67dfe@d2 1g2000prf.googl egroups.com...
    I'm populating a label with an amount like this:
    >
    lblBudget.Text = Generic_databas e_functions.Get Value("SELECT
    ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")
    >
    I want the amount in the label to be shown as "10.000" not "10000".
    How can I format the amount?

    I'm presuming that . is the thousand separator for the culture you're
    using...

    lblBudget.Text =
    Convert.ToDecim al(Generic_data base_functions. GetValue("SELEC T
    ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • staeri@gmail.com

      #3
      Re: Format text in label to amount

      On 9 Jan, 15:02, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
      <sta...@gmail.c omwrote in message
      >
      news:542351c6-f9e5-4714-be00-fbc6cef67dfe@d2 1g2000prf.googl egroups.com...
      >
      I'm populating a label with an amount like this:
      >
      lblBudget.Text = Generic_databas e_functions.Get Value("SELECT
      ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")
      >
      I want the amount in the label to be shown as "10.000" not "10000".
      How can I format the amount?
      >
      I'm presuming that . is the thousand separator for the culture you're
      using...
      >
      lblBudget.Text =
      Convert.ToDecim al(Generic_data base_functions. GetValue("SELEC T
      ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")
      >
      --
      Mark Rae
      ASP.NET MVPhttp://www.markrae.net
      Thank you for the help. Unfortunately I receive error message: "Input
      string was not in a correct format".

      (Yes, "." is the thousand separator).

      // S

      Comment

      • Mark Rae [MVP]

        #4
        Re: Format text in label to amount

        <staeri@gmail.c omwrote in message
        news:29f3724d-6997-4642-836d-9a8567691ea2@l1 g2000hsa.google groups.com...
        >lblBudget.Te xt =
        >Convert.ToDeci mal(Generic_dat abase_functions .GetValue("SELE CT
        >ISNULL(Sum(Bud get), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")
        >
        Thank you for the help. Unfortunately I receive error message: "Input
        string was not in a correct format".
        What datatype does GetValue return...?


        --
        Mark Rae
        ASP.NET MVP


        Comment

        • staeri@gmail.com

          #5
          Re: Format text in label to amount

          On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
          <sta...@gmail.c omwrote in message
          >
          news:29f3724d-6997-4642-836d-9a8567691ea2@l1 g2000hsa.google groups.com...
          >
          lblBudget.Text =
          Convert.ToDecim al(Generic_data base_functions. GetValue("SELEC T
          ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")
          >
          Thank you for the help. Unfortunately I receive error message: "Input
          string was not in a correct format".
          >
          What datatype does GetValue return...?
          >
          --
          Mark Rae
          ASP.NET MVPhttp://www.markrae.net
          It returns a string and it looks like this:

          Shared Function GetValue(ByVal strSP As String)
          Dim myConnection As New SqlConnection(C onnectionString )
          Dim myCommand As New SqlCommand(strS P, myConnection)
          myConnection.Op en()
          Dim strValue As String = myCommand.Execu teScalar().ToSt ring()
          myConnection.Cl ose()

          Return strValue
          End Function

          // S

          Comment

          • Mark Rae [MVP]

            #6
            Re: Format text in label to amount

            <staeri@gmail.c omwrote in message
            news:8cc75fdc-666d-4699-901c-8f219f73baba@s8 g2000prg.google groups.com...
            On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
            ><sta...@gmail. comwrote in message
            >>
            >news:29f3724 d-6997-4642-836d-9a8567691ea2@l1 g2000hsa.google groups.com...
            >>
            >lblBudget.Te xt =
            >Convert.ToDeci mal(Generic_dat abase_functions .GetValue("SELE CT
            >ISNULL(Sum(Bud get), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")
            >>
            Thank you for the help. Unfortunately I receive error message: "Input
            string was not in a correct format".
            >>
            >What datatype does GetValue return...?
            >
            It returns a string and it looks like this:
            >
            Shared Function GetValue(ByVal strSP As String)
            Dim myConnection As New SqlConnection(C onnectionString )
            Dim myCommand As New SqlCommand(strS P, myConnection)
            myConnection.Op en()
            Dim strValue As String = myCommand.Execu teScalar().ToSt ring()
            myConnection.Cl ose()
            >
            Return strValue
            End Function
            OK, then. Please try the following and tell me where it fails:

            Dim strGetValue As String
            strGetValue = Generic_databas e_functions.Get Value("SELECT
            ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")
            Dim decValue As Decimal
            decValue = Convert.ToDecim al(strGetValue)
            lblBudget.Text = decValue.ToStri ng("#.##0")



            BTW, you should really put some exception handling in your function or, at
            the very least, use the Using syntax... As it stands, any error in the
            ExecuteScaler line is liable to leave your connection open...


            --
            Mark Rae
            ASP.NET MVP


            Comment

            • staeri@gmail.com

              #7
              Re: Format text in label to amount

              On 10 Jan, 17:10, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
              <sta...@gmail.c omwrote in message
              >
              news:8cc75fdc-666d-4699-901c-8f219f73baba@s8 g2000prg.google groups.com...
              >
              >
              >
              >
              >
              On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
              <sta...@gmail.c omwrote in message
              >
              >news:29f3724 d-6997-4642-836d-9a8567691ea2@l1 g2000hsa.google groups.com...
              >
              lblBudget.Text =
              Convert.ToDecim al(Generic_data base_functions. GetValue("SELEC T
              ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")).ToString( "#.##0")
              >
              Thank you for the help. Unfortunately I receive error message: "Input
              string was not in a correct format".
              >
              What datatype does GetValue return...?
              >
              It returns a string and it looks like this:
              >
              Shared Function GetValue(ByVal strSP As String)
                     Dim myConnection As New SqlConnection(C onnectionString )
                     Dim myCommand As New SqlCommand(strS P, myConnection)
                     myConnection.Op en()
                     Dim strValue As String = myCommand.Execu teScalar().ToSt ring()
                     myConnection.Cl ose()
              >
                     Return strValue
              End Function
              >
              OK, then. Please try the following and tell me where it fails:
              >
              Dim strGetValue As String
              strGetValue = Generic_databas e_functions.Get Value("SELECT
              ISNULL(Sum(Budg et), 0) FROM vwPROJECTForeca st")
              Dim decValue As Decimal
              decValue = Convert.ToDecim al(strGetValue)
              lblBudget.Text = decValue.ToStri ng("#.##0")
              >
              BTW, you should really put some exception handling in your function or, at
              the very least, use the Using syntax... As it stands, any error in the
              ExecuteScaler line is liable to leave your connection open...
              >
              --
              Mark Rae
              ASP.NET MVPhttp://www.markrae.net- Dölj citerad text -
              >
              - Visa citerad text -
              The problem is solved! Your code was completely correct and it was a
              formula with additions containing the converted variables that caused
              the error. Thank you for the help!

              / S

              Comment

              • Mark Rae [MVP]

                #8
                Re: Format text in label to amount

                <staeri@gmail.c omwrote in message
                news:367e5b5a-87e1-4d71-81dc-ce16dd0e32da@21 g2000hsj.google groups.com...
                On 10 Jan, 17:10, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
                The problem is solved! Your code was completely correct and it was a
                formula with additions containing the converted variables that caused
                the error. Thank you for the help!
                Phew! Thought I was going crazy for a second... :-)


                --
                Mark Rae
                ASP.NET MVP


                Comment

                Working...