Hi i'm having a trouble with this i got 3 textbox and i format it to

Textbox1.Text = Format(Textbox1.Text, "Standard")
Textbox2.Text = Format(Textbox2.Text, "Standard")
Textbox3.Text = Format(Textbox3.Text, "Standard")

which give something like this
1,230.00
2,500.00
1,245.00

and when i add it
Textbox4.text = Val(Textbox1.Text) + Val(Textbox2.Text) + Val(Textbox3.Text)
the result is this
4.00

how can i sum it when the format is in "standard" or "percent"?

Recommended Answers

All 3 Replies

Val doesn't recognize a ',' as part of a number and stops converting the string there. Thus you end up with 1+2+1 = 4. Try this instead:
TextBox4.Text = Format((Double.Parse(Textbox1.Text) + Double.Parse(Textbox2.Text) + Double.Parse(Textbox3.Text)), "Standard")

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t1 As TextBox = New TextBox
        Dim t2 As TextBox = New TextBox
        Dim t3 As TextBox = New TextBox
        Dim t4 As TextBox = New TextBox
        t1.Text = "1,230.00"
        t2.Text = "2,500.00"
        t3.Text = "1,245.00"
        Dim sum As Decimal = isConvert(t1.Text) + _
                             isConvert(t2.Text) + _
                             isConvert(t3.Text)

        t4.Text = String.Format("{0:N2}", sum)
    End Sub
    Protected Function isConvert(ByVal str As String) As Decimal
        Return Decimal.Parse(str)
    End Function

thank you guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.