Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IsNumeric() returns crap

Status
Not open for further replies.

snerting

Programmer
Oct 20, 2005
52
debug.print IsNumeric("KR00")
True
debug.print IsNumeric("KR75")
True
debug.print IsNumeric("9D44")
True


What!? Is it taking like hexadecimal numbers and currency into consideration or what the **** is it doing? :)

I just want to see if a string contains anything else than 0...9 Guess I have to write a little algorithm myself or use regex.
 
well debug.print IsNumeric("KR00") = false when i run it and so does debug.print IsNumeric("KR75")

only debug.print IsNumeric("9D44") = true and i would have to assume because it is hexadecimal



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
9D44" is (believe or not) a valid number because scientific notation has the form "nnEnn" or "nnDnn".

If you need to get around that then build yourself a Function like
Code:
Public Function myIsNumeric(ByVal Value As String) As Boolean
    
    myIsNumeric = False
    
    If IsNumeric(Value) Then
        If Not (Value Like "*[deDE]*") Then
            myIsNumeric = True
        End If
    End If
    
End Function

(With credit to gmmastros in thread222-1264749)
 
It seems like the "KR" ones are valid numbers as I'm from Norway (as I guessed in my initial post: currency). If I change my regional settings to United States it will state "False". But then it will claim that IsNumeric("1000$") is a valid number - which is False when I change back to Norwegian.

I will refrain from saying how I really feel about Visual Basic in this case, as it would not be suited for young people that might be reading on these forums.
 

Its a matter of understanding the programming language and application (VBA).

If, for instance, you enter 1/2 in Excel, what do you suppose will happen. If you understand, you can either avoid problems or leverage the features.

Answer:
[highlight white][white]1/2 is interpreted by Excel as a DATE. With USA regional settings it's Jan 2 of the CURRENT year.[/white][/highlight]


Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
And gmmastros just posted this clever trick on that other thread
Code:
IsNumeric ( SomeString & "E0" )
which gets returns FALSE when "SomeString" is "9D44" or "1000$".
 
you can also use regexp with [0-9]. i have seen posting here. but i can't remember which post
 
Of course I can use regexp. I can use a lot of things to solve this pretty simple problem.

That's not the point.

I wouldn't say that the function text:
"IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False."

..in any way states that what will be considered a number is depending on what my regional settings currently are set to, and that currency and for all I know lots of other stuff are taken into consideration.

I have seen lots of implementations of similar functions in other languages, but neither of them have dived into currency and other oddities.

In my opinion it's dirty, very dirty. I pretty much find IsNumeric useless now, unless I want to check one character only.

Surely Skip, you can say I should embrace the language and it's features, but I dont really think I will in this case. I find the behavior horrific and "dangerous" ;).

At least it would help if the function description actually said _something_ regarding localization etc. I bet I'm not the only one who has fallen into the pit of using this function and assuming letters wont be accepted.

When I first saw that "KR75" returned True, I made a joke about it being Norwegian currency. Kind of amusing that I was actually right.
 
lol excellent - i'm off to Iceland end of this month they use KR as well, if I meet any programmers, I'll find out if they can use IsNumeric ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top