By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,986 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,986 IT Pros & Developers. It's quick & easy.

IsNumeric Function

P: 5
Hi,
The program that I have to make is suppose to check if the things I entered in the textbox is numeric and also if it's 9 digits. I tried a lot of ways to do it but none of them seem to work. Maybe someone can help me. This is my code for it:

Private Function TestInput() As Boolean

If IsNumeric(txtID.Text) and Len(Val(txtID.text)) Then
MsgBox("Please enter an appropriate FID.", MsgBoxStyle.Exclamation, "Enter FID Properly")
txtFID.Focus()
Return False
End If
End Function

Thanks
Nov 20 '06 #1
Share this Question
Share on Google+
8 Replies


Expert 5K+
P: 8,434
This might be some help (just off the top of my head, not tested)
Expand|Select|Wrap|Line Numbers
  1. Private Function TestInput() As Boolean
  2.   If IsNumeric(txtID.Text) and Len(Val(txtID.text) = 9) Then
  3.     TestInput = True
  4.   Else
  5.     MsgBox("Please enter an appropriate FID.", MsgBoxStyle.Exclamation, "Enter FID Properly")
  6.     txtFID.SetFocus()
  7.     TestInput = False ' (Not strictly necessary, as False is default)
  8.   End If
  9. End Function
Also note, we may be using different versions of VB - this should work in VB6.

Also, according to the manual, the input for IsNumeric must be a variant, not a string. I haven't checked this.
Nov 20 '06 #2

P: 5
Yeah unfortunately, that doesn't work. It might be b/c i'm using VB5 but don't know. Thanks for your effort though
Nov 20 '06 #3

Expert 5K+
P: 8,434
Yeah unfortunately, that doesn't work. It might be b/c i'm using VB5 but don't know. Thanks for your effort though
Hm... you could try leaving out the IsNumeric check. Try this...
Expand|Select|Wrap|Line Numbers
  1. Private Function TestInput() As Boolean
  2.   If Len(Format(Val(txtID.text))) = 9) Then
  3.     TestInput = True
  4.   Else
  5.     MsgBox("Please enter an appropriate FID.", MsgBoxStyle.Exclamation, "Enter FID Properly")
  6.     txtFID.SetFocus()
  7.     TestInput = False ' (Not strictly necessary, as False is default)
  8.   End If
  9. End Function
Incidentally, I think we'll need more information than "doesn't work" to help further. It's a bit vague.
Nov 20 '06 #4

P: 5
Yeah I finally got it. I just made 2 if statements and it works perfectly.


'return false if it is not all numbers inputted in the textbox
If IsNumeric(txtID.Text) = False Then
MsgBox("Please enter an appropriate ID.", MsgBoxStyle.Exclamation, "Enter ID Properly")
txtFID.Focus()
Return False
End If

'return false if it's not 9 digits long
If Len(txtID.Text) <> 9 Then
MsgBox("Please enter an appropriate ID.", MsgBoxStyle.Exclamation, "Enter ID Properly")
txtFID.Focus()
Return False
End If

Thanks for your help killer
Nov 20 '06 #5

Expert 5K+
P: 8,434
No worries. I'm glad it helped.

I'm curious, though - based on the .Focus method and the Return statement, this is not VB6 or earlier. Must be some version of VB.Net, correct?
Nov 20 '06 #6

P: 5
Oh yeah...sorry...it's VB.Net. I guess it's a lot different from VB6 eh?
Nov 20 '06 #7

Expert 5K+
P: 8,434
Oh yeah...sorry...it's VB.Net. I guess it's a lot different from VB6 eh?
Details do differ quite a bit, but the logic tends to work the same across lots of languages, so we can often help. Feel free to try us. (As with this thread, you may need to adjust the answers slightly.)

You could also try the .Net forum when you have questions, as they may have more directly related experience.
Nov 20 '06 #8

P: 5
Details do differ quite a bit, but the logic tends to work the same across lots of languages, so we can often help. Feel free to try us. (As with this thread, you may need to adjust the answers slightly.)

You could also try the .Net forum when you have questions, as they may have more directly related experience.
Oh okay then...thanks:D
Nov 20 '06 #9

Post your reply

Sign in to post your reply or Sign up for a free account.