I'm new to VB programming. I have two variables - one hrsWorked as String and hoursWorked as Double. I got hours worked from user into hrsWorked. I know VB can convert the inut string hrsWorked to hoursWorked for me if the user enters, say 45.8. But what if user enters the wrong input, say, "hello", instead of 45.8? I want to test to make sure that user did not enter "hello" or any other character string. How do I test the user input in hrsWorked or what VB function can I use to test it before I assign hoursWorked = hrsWorked?
Thanks for any comment/help
Scott LyslePosted Jan 10, 2009, 12:28 PM
You can first prevent the user from entering anything but a decimal:
Private
Sub TextBox1_KeyPress(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar) And e.KeyChar <> ".") Thene.Handled =
True End If End Sub