You can try converting to a byte (range 0 - 255) and handle the error from out of range values... unless you plan to allow an age of more than 255 years.
Code:Option Explicit Private Sub Form_Load() Do While Not IsValidAge(InputBox("Enter person's age")) MsgBox "Invalid value for age" Loop End Sub Public Function IsValidAge(strAge As String) As Boolean Dim bytAge As Byte On Error GoTo ErrHandler bytAge = CByte(strAge) IsValidAge = True Exit Function ErrHandler: Err.Clear End Function




Reply With Quote