Hello - I'm extremely new to VB but appreciate any help you can offer.
I am trying to validate input in a textbox where a GPA is entered. I want to give the user an error message when he/she does not enter anything or enters a number that is not between 0 and 4. I have done a keypress event to limit the characters that can be entered to numbers, backspace, and the period and this is working fine.
I'm doing this as a function and this is my code so far:
Function IsGoodInput(ByVal number As String) As Boolean
If txtgpa.Text = "" Or Val(txtgpa.Text) > 4 Then
MsgBox("Please enter a number between 0 and 4.", "Input error.")
txtgpa.Focus()
Return False
Else
Return True
End If
I've tried this a few ways and I either get a conversion error or an invalid cast error. Thank you for any assistance.
I am trying to validate input in a textbox where a GPA is entered. I want to give the user an error message when he/she does not enter anything or enters a number that is not between 0 and 4. I have done a keypress event to limit the characters that can be entered to numbers, backspace, and the period and this is working fine.
I'm doing this as a function and this is my code so far:
Function IsGoodInput(ByVal number As String) As Boolean
If txtgpa.Text = "" Or Val(txtgpa.Text) > 4 Then
MsgBox("Please enter a number between 0 and 4.", "Input error.")
txtgpa.Focus()
Return False
Else
Return True
End If
I've tried this a few ways and I either get a conversion error or an invalid cast error. Thank you for any assistance.