Results 1 to 6 of 6

Thread: Format Result of Textbox "0.00"

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    Format Result of Textbox "0.00"

    Does anyone know how to fix this to show the result within the textbox like this: "0.00"

    Right now, it appears like this: "252525."
    I'm new to VBA and am trying to piece this together properly...
    Everything seems to work great - except for this format problem...

    Code:
    Sub MyCalcQu()
        If IsNumeric(TextBox7.Text) Then
        If IsNumeric(TextBox8.Text) Then
        If IsNumeric(TextBox13.Text) Then
            TextBox3.Value = CDbl(TextBox7.Value) + CDbl(TextBox8.Value) + CDbl(TextBox13.Value)
    
    'format the contents of the TextBox3 result
            TextBox3.Value = Format(TextBox7.Value + TextBox8.Value + TextBox13.Value, "0.00")
        
        End If
        End If
        End If
    End Sub
    
    Private Sub TextBox7_Change()
        MyCalcQu
    End Sub
    Private Sub TextBox8_Change()
        MyCalcQu
    End Sub
    Private Sub TextBox13_Change()
        MyCalcQu
    End Sub
    Thanks! Chris

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,024

    Re: Format Result of Textbox "0.00"

    Hi!!!

    Are you using MS Access?


  3. #3
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Format Result of Textbox "0.00"

    The problem is, you're trying to format a concatenated string. The values in your textboxes are "25", not 25. You converted to double to to get the value for your final textbox, but when formatting, you didn't convert.

    "25" + "25" + "25" = "252525"
    25 + 25 + 25 = 75

    Just change
    VB Code:
    1. TextBox3.Value = Format(TextBox7.Value + TextBox8.Value + TextBox13.Value, "0.00")
    to
    VB Code:
    1. TextBox3.Value = Format(cDbl(TextBox3.Value), "0.00")

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    Re: Format Result of Textbox "0.00"

    This is for a user form in MS Excel.
    The user plugs in their monthly numbers hits save/submit and this code sends their data into a spreadsheet (database within excel) - that auto-generates a bunch of charts used in executive briefings.....

    Example: the user plugs in:
    Number Shipped:_9__
    Tot Days of All Shipped: _53__
    Their result appears below like this: (so they can see the calculation occur
    as they input their 2 numbers above)
    Result:__5.89___

    The problem with this is that the result field (TextBox3) is not adding the 3 numbers together -- it's sticking them together & showing a long result:
    by putting '25' from textbox 7
    and '25' from textbox 8
    and '25' from textbox 13
    together like this: '252525.' within this in the result field (Textbox3)

    I need it to ADD the (3) 25's together tb7+tb8+tb13 and put the result into tb3 as: "75" (not 252525.)

  5. #5
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Format Result of Textbox "0.00"

    see the post directly above yours

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Location
    OK - USA
    Posts
    29

    Thumbs up Re: Format Result of Textbox "0.00"

    Quote Originally Posted by mikeyc1204
    The problem is, you're trying to format a concatenated string. The values in your textboxes are "25", not 25. You converted to double to to get the value for your final textbox, but when formatting, you didn't convert.

    "25" + "25" + "25" = "252525"
    25 + 25 + 25 = 75

    Just change
    VB Code:
    1. TextBox3.Value = Format(TextBox7.Value + TextBox8.Value + TextBox13.Value, "0.00")
    to
    VB Code:
    1. TextBox3.Value = Format(cDbl(TextBox3.Value), "0.00")
    ************
    Mikey: The single line of code is EXACTLY what it needed to correct the problem!!
    You are awesome! -- Thank you verrrrry much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width