Jump to content

Maximum number limit

- - - - -

  • Please log in to reply
No replies to this topic

#1
mcallinder

mcallinder

    Newbie

  • Members
  • Pip
  • 3 posts
Hello all! Simple question (I hope) that I haven't been able to find the answer too.

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users