ADO DOT NET Posted February 2, 2007 Posted February 2, 2007 I always get invalid number error while using this: Dim MyRes As Boolean Dim MyInt As Integer = Integer.TryParse(NumericUpDown1.Value, MyRes) If MyInt < 1 Or MyInt > 65535 Then MsgBox("invalid number") End If I am using VB.NET 2005, .NET Framework 2.0.WindowsApplication1.zip Quote
*Experts* Nerseus Posted February 2, 2007 *Experts* Posted February 2, 2007 I believe you've got your Boolean and Integer swapped. Try this: Dim MyInt As Integer Dim MyRes As Boolean = Integer.TryParse(NumericUpDown1.Value, MyInt) If MyInt < 1 Or MyInt > 65535 Then MsgBox("invalid number") End If The second param to TryParse is the parsed integer value. The return of the function is true/false on whether the parsing worked. Also, it looks like you want to parse a short integer. Maybe replace Integer with UShort above. Then you'd only have to check against 0 (if that's an invalid value for you). Just an observation, not critical to your question. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Administrators PlausiblyDamp Posted February 2, 2007 Administrators Posted February 2, 2007 Just to add - putting Option Strict On at the top of your source files will catch a lot of these mistakes at compile time rather than run time. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.