Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
http://i67.tinypic.com/5kfyo0.jpg

How can i fix that sum. 1+2 = 12 not 3. This my code vb.net

Private Sub btnHitung_Click(sender As Object, e As EventArgs) Handles btnHitung.Click
    txtJumlahB.Text = (txtStokSisa.Text + txtBarangM.Text)
End Sub


thanks before

What I have tried:

i try sum from google search. but i can't find the same wrong with this.
Posted
Updated 19-Apr-18 17:22pm

1 solution

TextBox's always return strings, never integers. A string, "1", is not the same as an integer, 1.

You're concatenating two strings together, "1" + "2" = "12".

You have to convert the string to integers in order to add them together. Look into Integer.TryParse()[^] to accomplish that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900