none
Validate a textbox range between 1 - 2,147,483,647 RRS feed

  • Question

  • This one is an easy question.

    Ok, I want to validate a textbox's value to be between 1 and 2,147,483,647.

    This code works because there is no error.

    I wasn't going to put any message boxes in the catch exceptions area because I dont want to show any

    messages except the errorprovider message. Is there a better way of handling a range of numbers?

    I am trying some code here like this....

    Try If IsNumeric(txtOdometer.Text) OrElse Integer.Parse (txtOdometer.Text) < Integer.MinValue _

    OrElse Integer.Parse(txtOdometer.Text) > Integer.MaxValue Then ErrPFuelLog.SetError(txtOdometer, "Please enter a numeric value between " & _

    Integer.MinValue & " and " & Integer.MaxValue) End If Catch ex As FormatException Catch ex As OverflowException Catch ex As Exception End Try

    Friday, June 8, 2012 12:52 AM

Answers

  • Ok think I found a good way of doing this. Still if anyone has a better way of doing this let me know.

    'Required, Must be between 1 and 2147483647 and numeric
      Dim value As Integer = 0
      If Not Integer.TryParse(txtOdometer.Text, value) OrElse CInt(txtOdometer.Text) < 1 Then
          ErrPFuelLog.SetError(txtOdometer, "Enter a numeric number between 1 and 2,147,483,647")
            Else
                ErrPFuelLog.SetError(txtOdometer, "")
            End If

    • Marked as answer by achurchill Friday, June 8, 2012 1:46 AM
    Friday, June 8, 2012 1:23 AM

All replies

  • Well I should say

    OrElse Integer.Parse  (txtOdometer.Text) < 1

    to correctly get it in range.

    Friday, June 8, 2012 12:55 AM
  • Ok think I found a good way of doing this. Still if anyone has a better way of doing this let me know.

    'Required, Must be between 1 and 2147483647 and numeric
      Dim value As Integer = 0
      If Not Integer.TryParse(txtOdometer.Text, value) OrElse CInt(txtOdometer.Text) < 1 Then
          ErrPFuelLog.SetError(txtOdometer, "Enter a numeric number between 1 and 2,147,483,647")
            Else
                ErrPFuelLog.SetError(txtOdometer, "")
            End If

    • Marked as answer by achurchill Friday, June 8, 2012 1:46 AM
    Friday, June 8, 2012 1:23 AM