467,161 Members | 852 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

IsNumeric Function

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
  • viewed: 20733
Share:
8 Replies
Expert 8TB
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
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 8TB
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
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 8TB
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
Oh yeah...sorry...it's VB.Net. I guess it's a lot different from VB6 eh?
Nov 20 '06 #7
Expert 8TB
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
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.

Similar topics

8 posts views Thread by eje | last post: by
4 posts views Thread by Eugene Anthony | last post: by
14 posts views Thread by Kenny | last post: by
8 posts views Thread by John Bowman | last post: by
10 posts views Thread by michele | last post: by
7 posts views Thread by Nathan Truhan | last post: by
9 posts views Thread by Kimelia Schiles | last post: by
12 posts views Thread by sck10 | last post: by
9 posts views Thread by =?Utf-8?B?VG9ueQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.