473,215 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,215 software developers and data experts.

IsNumeric gives error

eje
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 Function Numeric(ByVal value) As Boolean
If CType(value, String).Length = 0 Then
m_msg = "Value is empty"
Return False
End If
If IsNumeric(value) Then
Return True
Else
m_msg = "Value isn't numeric"
Return False
End If

End Function

What to do?
Eje
Jul 21 '05 #1
8 2272
Hi Eje,

You can set Option Strict On to solve this problem, I think that that makes
it probably direct clear to you.

Cor

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 Function Numeric(ByVal value) As Boolean
If CType(value, String).Length = 0 Then
m_msg = "Value is empty"
Return False
End If
If IsNumeric(value) Then
Return True
Else
m_msg = "Value isn't numeric"
Return False
End If

End Function

What to do?
Eje

Jul 21 '05 #2
-----Original Message----- Hi Cor
I want to validate a value of unknown datatype. That's
why I can't use Option Strict On

Eje
Hi Eje,

You can set Option Strict On to solve this problem, I think that that makesit probably direct clear to you.

Cor

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 Function Numeric(ByVal value) As Boolean
If CType(value, String).Length = 0 Then
m_msg = "Value is empty"
Return False
End If
If IsNumeric(value) Then
Return True
Else
m_msg = "Value isn't numeric"
Return False
End If

End Function

What to do?
Eje

.

Jul 21 '05 #3
You should still always have option strict on.

You can either make the parameter an Object, or have several different
versions of the method, with each one having a parameter of a different type
(and then potentially have them all forwarded to one method that contains
all the actual logic).

Now, is what being passed here an actual string, or something else? Can you
reproduce this behavior by just calling IsNumeric from a little test program
and passing it in some string that cannot be converted to a numeric?

<an*******@discussions.microsoft.com> wrote in message
news:27*****************************@phx.gbl...
-----Original Message-----

Hi Cor
I want to validate a value of unknown datatype. That's
why I can't use Option Strict On

Eje
Hi Eje,

You can set Option Strict On to solve this problem, I

think that that makes
it probably direct clear to you.

Cor

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 Function Numeric(ByVal value) As Boolean
If CType(value, String).Length = 0 Then
m_msg = "Value is empty"
Return False
End If
If IsNumeric(value) Then
Return True
Else
m_msg = "Value isn't numeric"
Return False
End If

End Function

What to do?
Eje

.

Jul 21 '05 #4
Hi Eje,

That was what I was thinking however would let you give the answer.

As usuall would my answer have been almost the same as from Marina when I
had answered you before her, and therefore I add nothing to her answer.

:-)

Cor
Jul 21 '05 #5
:)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uM***************@TK2MSFTNGP11.phx.gbl...
Hi Eje,

That was what I was thinking however would let you give the answer.

As usuall would my answer have been almost the same as from Marina when I
had answered you before her, and therefore I add nothing to her answer.

:-)

Cor

Jul 21 '05 #6
Thanks for helping me Marina and Cor.
First to answer your question, Marina. In my actual
application the passed values are strings. I import
textfiles with delimiter separated records and have to
check every value before I pass the values on to the
database.
I made the following tests (See my comments in the
function Test):

Option Strict On
'...

Public Function test() As Boolean
Dim indata As Object
Dim MyCheck As Boolean
indata = "53"
MyCheck = Numeric(indata) 'No problem
indata = "45 abc"
MyCheck = Numeric(indata) 'Still gives error
indata = "abc"
MyCheck = Numeric(indata) 'Still gives error
End Function

Public Function Numeric(ByVal MyVar As Object) As
Boolean
Dim MyCheck As Boolean
MyCheck = IsNumeric(MyVar)
Return MyCheck
End Function

Compare this example from the Help:

Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.

-----Original Message-----
You should still always have option strict on.

You can either make the parameter an Object, or have several differentversions of the method, with each one having a parameter of a different type(and then potentially have them all forwarded to one method that containsall the actual logic).

Now, is what being passed here an actual string, or something else? Can youreproduce this behavior by just calling IsNumeric from a little test programand passing it in some string that cannot be converted to a numeric?
<an*******@discussions.microsoft.com> wrote in message
news:27*****************************@phx.gbl...
>-----Original Message-----

Hi Cor
I want to validate a value of unknown datatype. That's
why I can't use Option Strict On

Eje
>Hi Eje,
>
>You can set Option Strict On to solve this problem, I

think that that makes
>it probably direct clear to you.
>
>Cor
>
>
>> 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 Function Numeric(ByVal value) As Boolean
>> If CType(value, String).Length = 0 Then
>> m_msg = "Value is empty"
>> Return False
>> End If
>> If IsNumeric(value) Then
>> Return True
>> Else
>> m_msg = "Value isn't numeric"
>> Return False
>> End If
>>
>> End Function
>>
>> What to do?
>> Eje
>
>
>.
>

.

Jul 21 '05 #7
Hi Anon,

Why not as this with option Strict On
See inline bellow

I hope this helps?

Cor

Option Strict On
'...

Public Function test() As Boolean
Dim indata As Object
Dim MyCheck As Boolean
indata = "53"
MyCheck = Numeric(indata.ToString) 'No problem
indata = "45 abc"
MyCheck = Numeric(indata.ToString) 'Still gives error
indata = "abc"
MyCheck = Numeric(indata.TosString) 'Still gives error
End Function Public Function Numeric(ByVal MyVar As String) As
Boolean
Dim MyCheck As Boolean
MyCheck = IsNumeric(MyVar)
Return MyCheck
End Function

Compare this example from the Help:

Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.

-----Original Message-----
You should still always have option strict on.

You can either make the parameter an Object, or have

several different
versions of the method, with each one having a parameter

of a different type
(and then potentially have them all forwarded to one

method that contains
all the actual logic).

Now, is what being passed here an actual string, or

something else? Can you
reproduce this behavior by just calling IsNumeric from a

little test program
and passing it in some string that cannot be converted

to a numeric?

<an*******@discussions.microsoft.com> wrote in message
news:27*****************************@phx.gbl...

>-----Original Message-----
Hi Cor
I want to validate a value of unknown datatype. That's
why I can't use Option Strict On

Eje

>Hi Eje,
>
>You can set Option Strict On to solve this problem, I
think that that makes
>it probably direct clear to you.
>
>Cor
>
>
>> 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 Function Numeric(ByVal value) As Boolean
>> If CType(value, String).Length = 0 Then
>> m_msg = "Value is empty"
>> Return False
>> End If
>> If IsNumeric(value) Then
>> Return True
>> Else
>> m_msg = "Value isn't numeric"
>> Return False
>> End If
>>
>> End Function
>>
>> What to do?
>> Eje
>
>
>.
>

.

Jul 21 '05 #8
Hi cor,
If you still check this. I found the error. I had to
change an option in the menu Debug/Exceptions

Thanks for your help

Eje
-----Original Message-----
Hi Anon,

Why not as this with option Strict On
See inline bellow

I hope this helps?

Cor

Option Strict On
'...

Public Function test() As Boolean
Dim indata As Object
Dim MyCheck As Boolean
indata = "53"
MyCheck = Numeric(indata.ToString) 'No problem
indata = "45 abc"


MyCheck = Numeric(indata.ToString) 'Still gives

error
indata = "abc"
MyCheck = Numeric(indata.TosString) 'Still gives

error
End Function

Public Function Numeric(ByVal MyVar As String) As
Boolean
Dim MyCheck As Boolean
MyCheck = IsNumeric(MyVar)
Return MyCheck
End Function

Compare this example from the Help:

Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.

>-----Original Message-----
>You should still always have option strict on.
>
>You can either make the parameter an Object, or have

several different
>versions of the method, with each one having a parameter
of a different type
>(and then potentially have them all forwarded to one

method that contains
>all the actual logic).
>
>Now, is what being passed here an actual string, or

something else? Can you
>reproduce this behavior by just calling IsNumeric
from a little test program
>and passing it in some string that cannot be converted

to a numeric?
>
><an*******@discussions.microsoft.com> wrote in message
>news:27*****************************@phx.gbl...
>>
>> >-----Original Message-----
>> Hi Cor
>> I want to validate a value of unknown datatype.
That's >> why I can't use Option Strict On
>>
>> Eje
>>
>> >Hi Eje,
>> >
>> >You can set Option Strict On to solve this problem, I >> think that that makes
>> >it probably direct clear to you.
>> >
>> >Cor
>> >
>> >
>> >> 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 Function Numeric(ByVal value) As Boolean
>> >> If CType(value, String).Length = 0 Then
>> >> m_msg = "Value is empty"
>> >> Return False
>> >> End If
>> >> If IsNumeric(value) Then
>> >> Return True
>> >> Else
>> >> m_msg = "Value isn't numeric"
>> >> Return False
>> >> End If
>> >>
>> >> End Function
>> >>
>> >> What to do?
>> >> Eje
>> >
>> >
>> >.
>> >
>
>
>.
>

.

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: DCM Fan | last post by:
SELECT ISNUMERIC('. ') 1 SELECT CAST('. ' AS ) Syntax error converting the varchar value '. ' to a column of data type . Any thoughts as to why SQL Server 7.0 considers '. ' to be...
4
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...
14
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
10
by: crowl | last post by:
I have a pocket pc project in c#. From a textbox i have to verify if the input is numeric. I have found in the msdn a sample like this: textbox1.numeric = true / false. But this do not work in...
3
by: martin | last post by:
Hi, is there a dotnet function (other than the old isnumeric from VB) to check whether an object is numeric or not. also I notice that all the old vb functions such as split / isnumeric /...
3
by: Radith Silva | last post by:
Dear All; Thanx for helpt with previous question. Still learning?? FROM A VB 6.0 BOOK: any way; I have used IsNumeric function and check all namespace conflicts and all and nothing seems...
10
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...
8
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...
17
by: MLH | last post by:
I have tested the following in immed window: ?isnumeric(1) True ?isnumeric(1.) True ?isnumeric(1.2) True ?isnumeric(1.2.2)
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.