I would like to limit the numerical input of a text box not to exceed 160. Here is what I've been trying:
'
Catch HoursWorkedException As Exception
If HoursWorkedInteger > MAX_HOURS_Integer Then
MessageBox.Show("The hours worked cannot exceed 160.", "Try Again", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With HoursWorkedTextBox
.Focus()
.SelectAll()
End With
End If
MAX_HOURS_Integer is a constant set to 160. The project is running fine, it just ignores this exception. Any idas?
SOLVED -
Figured out how to do this with an If Then statement rather than a catch. For anyone else with a similar problem:
Try
'Convert the hours worked if a valid number was input.
HoursWorkedInteger = Integer.Parse(HoursWorkedTextBox.Text)
'Ensure the hours worked do not exceed the maximum.
If (HoursWorkedInteger > MAX_HOURS_Integer) Then
'Display an error if hours worked exceed maximum.
MessageBox.Show("The hours worked cannot exceed 160.", "Try Again", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
With HoursWorkedTextBox
.Focus()
.SelectAll()
End With
Else....
Edited by mcallinder, 26 January 2011 - 03:32 PM.


Sign In
Create Account

Back to top









