Search This Blog

Thursday, November 4, 2010

How to prevent non-numeric input in VB.NET?

Programmer Question

I'm working on a program that requires the user to input an integer. How do I prevent the user from entering a non-numeric value? I tried using the IsNumeric() function but I get an error before I can use it. I get the error at the console.read, before I can call the IsNumeric() function. Here is my code:



Dim num As Integer

Console.Write("enter num:")
num = Console.ReadLine

If IsNumeric(num) = True Then
Console.WriteLine("valid. num = " & num)
Else
Console.WriteLine("invalid")
End If


Any help is greatly appreciated.



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails