Chew Chew - 2 years ago 104 Question

vb how to let btn know textbox value for increase and decrease?

enter image description here

how i let my button know my text box value. i want to do is let my button know about my value when i insert 10 if i click + button will be 11 if i click - button will be 9 what should i do?

here is my addbtn code

i = i + 1
txtqty.Text = CStr(i)

this is my decrease btn code

i = i - 1
txtqty.Text = CStr(i)

Answer Source

You need to convert the content of the TextBox to an integer, perform your calculation and then reassign the calculated value back to the textbox

Dim value as Int
If Int32.TryParse(txtqty.Text, value) Then
   value = value + 1
   txtqty.Text = value.ToString()
   MessageBox.Show("The textbox doesn't contain a valid number")
End If

Of course when you deal with user input you should take extra care on checking if the input is good for the task that you want to perform. Thus I have used Int32.TryParse that return false if the content of the textbox is not a valid integer number.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download