add textbox values?

Opticknerve

New member
Joined
Jun 3, 2014
Messages
3
Programming Experience
Beginner
Hey Guys im still new to programming....

Here is my code
Public Class Form1

    Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
        Dim Val1, Val2, Val3 As Integer

        Val1 = System.Convert.ToInt32(tbVal1.Text)
        Val2 = System.Convert.ToUInt32(tbVal2.Text)
        Val3 = Val1 / Val2

        tbVal3.Text = System.Convert.ToString(Val3)
    End Sub

    Private Sub btnMulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMulti.Click
        Dim Val4, Val5, Val6 As Integer

        Val4 = System.Convert.ToInt32(tbVal4.Text)
        Val5 = System.Convert.ToUInt32(tbVal5.Text)
        Val6 = Val4 * Val5

        tbVal6.Text = System.Convert.ToString(Val6)
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        tbVal7.Text = tbVal3.Text + tbVal6.Text
    End Sub

End Class

I want to add the value of tbVal3 and tbVal6 into tbVal7. Instead of getting 10 i get 91.
 
Last edited by a moderator:
Firstly, I have fixed the formatting of your code snippet using formatting tags to restore indenting and also removed all those pointless empty lines that just made it harder to read. Please take the time to make your posted code as easy to read as possible. Otherwise, you're wasting the time of those who are volunteering it to help you.

As for the question, think about what you're doing differently in the three cases. Why is it that you convert the the Strings from the TextBoxes to Integers in two cases, which work, and you don't in the third, which doesn't?

Also, where you do convert the data, are you intentionally using Convert.ToInt32 for one of the values and Convert.ToUInt32 for the other?
 
Back
Top