Click here to Skip to main content
15,311,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:[^]
how can i put the negative number to change textbox?like the picture below

here my code!!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim i As Double = txtpayment.Text
       i -= txtname.Text
       txtbalance.Text = +-i.ToString

   End Sub
Updated 3-Mar-14 1:22am

1 solution

Well, I would suggest starting by not trying to subtract a name from a number - it generally doesn't work too well...

I would also suggest using int.TryParse to convert the textbox values to numbers - with error reporting if the user types a non-numeric value.
Dim charge As Integer
If Not Integer.TryParse(txtCharge.Text, charge) Then
    ' Report error
End If
Dim payment As Integer
If Not Integer.TryParse(txtPayment.Text, payment) Then
    ' Report error
End If
Dim balance As Integer = charge - payment
txtBalance.Text = balance.ToString()
Member 10617989 3-Mar-14 11:36am
sorry dude but your answer is not exactly my what i want to this case i want to compute the charge and payment so charge - payment = balance .... so this is the problem when the answer is become negative i think this not a is a change i trying to say if the answer is become negative the answer fill to another textbox which is the change ....
OriginalGriff 3-Mar-14 11:42am
Ah! You need to explain these things... :laugh:
Do exactly as above, but replace the last line with:
If balance >= 0 Then
txtBalance.Text = balance.ToString()
txtChange.Text = balance.ToString()
End If
Member 10617989 3-Mar-14 19:16pm
show me the whole code so i can understand what your saying

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