473,513 Members | 2,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IsNumeric Function

5 New Member
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
8 21168
Killer42
8,435 Recognized Expert Expert
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
munkeyb0i
5 New Member
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
Killer42
8,435 Recognized Expert Expert
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
munkeyb0i
5 New Member
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
Killer42
8,435 Recognized Expert Expert
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
munkeyb0i
5 New Member
Oh yeah...sorry...it's VB.Net. I guess it's a lot different from VB6 eh?
Nov 20 '06 #7
Killer42
8,435 Recognized Expert Expert
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
munkeyb0i
5 New Member
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

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

Similar topics

8
2293
by: eje | last post by:
IsNumeric(value) should return false if value "can not be successfully converted to a Double." Instead I get the following error message: "Input string was not in a correct format." I use the following function in a validating class to use when needed. (Value = H880118A gave the error (like other 'unconvertible' strings)) Public...
4
13261
by: Eugene Anthony | last post by:
I have received the following feedback for the two functions bellow: "The ISNUMERIC test is WORTHLESS for checking for an INT value, because ISNUMERIC will happily accept DOUBLE values, such as 89.11998811777 and other values that are simply *NOT* INT values." <% function isZip(input)
14
40104
by: Kenny | last post by:
Hello, I would like to know if the function IsNumeric requires a header like #include <iostream> to be functionnal thanks ken
8
2599
by: John Bowman | last post by:
Hello, Does anyone have a good/reliable approach to implementing an IsNumeric() method that accepts a string that may represent a numerical value (eg. such as some text retrieved from an XML file)? Thus if you pass it "1" or "5.12345" it returns true, but "1b3q" it returns false? I know VB has this sort of function, but was wondering how to...
10
2771
by: michele | last post by:
I have a problem with VB.Net and IsNumeric() function because it always returns FALSE even the string can be a number. There is another strange thing, the same program (it is a test) runs good on one and doesn't run an another one. The program test is very simple, just a form with a text box and a button. The text box has a validation rule...
8
3217
by: Dave | last post by:
I'm trying to import Microsoft.VisualBasic to use the IsNumeric function in my C# code but all I see is: Microsoft.VisualBasic.VBCodeProvider while using Intellisense... From samples shouldn't I see Microsoft.VisualBasic.Information.IsNumeric? Thanks
7
2360
by: Nathan Truhan | last post by:
All, I think I may have uncovered a bug in the IsNumeric function, or at least a misunderstanding on functionality. I am writing a Schedule Of Classes Application for our campus and have a section that lists the Times, Buildings and rooms for courses. In this section I have a function called PadCell that takes3 parameters, one the value,...
9
8967
by: Kimelia Schiles | last post by:
Hi, I am new to C#, and I am a VB programmer. I would like to know whether there is any function in C# that can is similar to IsNumeric in VB?
12
3041
by: sck10 | last post by:
Hello, I am trying to determine if a value is NOT numeric in C#. How do you test for "Not IsNumeric"? protected void fvFunding_ItemInserting_Validate(object sender, FormViewInsertEventArgs e) if (e.NewValues != "" && Not IsNumeric(e.NewValues)) {
9
2301
by: =?Utf-8?B?VG9ueQ==?= | last post by:
Can anybody tell why IsNumeric("5-") is true?
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.