Hello folks,
can i detect if a text box is showing 15 and descending and then perform an action?
Printable View
Hello folks,
can i detect if a text box is showing 15 and descending and then perform an action?
Hey,
How are you wanting to go about doing this detection?
Is it based on the user clicking a button? Or is it when the user enters something into the textbox and then leaves the textbox?
Can you provide some more information?
If for instance you wanted to do it on the click event of a button, you could use:
If however, you wanted to do it when the user left the textbox, you could do the same as the above, but you might want to use the Leave Event, or the TextChanged Event.Code:Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text <> String.Empty AndAlso CInt(TextBox1.Text) <= 15 Then
MessageBox.Show("Entry is less than or equal to 15")
End If
End Sub
Gary
As gep said, depending on where you want to use the code will determine in which event handler you will place the code, but your code would look something like this:
Code:Dim result As Integer
If Integer.TryParse(TextBox1.Text, result) AndAlso result <= 15 Then
' Do Some action
End If
Agreed, should use the Integer.TryParse rather then CInt.
Gary
thanks guys for your suggestions.
To add to my question
The information is automatically populated from another application which is updated via a timer so every ten seconds it updates
The number goes up and down I only want to do an action when its at 15 and descending
Sounds like the TextChanged Event is the one that you are after then.
Gary