IsNumber bug?

MotoMusher

Active Member
Licensed User
Longtime User
Can someone try this and confirm? I have it in a button event for testing.

This says it is a number:
B4X:
    Dim z As String = "SHE7150"
    If IsNumber(z) = True Then
        Msgbox("IsNumber", "")
    Else
        Msgbox("Not a Number", "")
    End If

This correctly says it is not a number, along with nearly every other combination I try:
B4X:
    Dim z As String = "SHZ7150"
    If IsNumber(z) = True Then
        Msgbox("IsNumber", "")
    Else
        Msgbox("Not a Number", "")
    End If


I am running through a cursor and it keeps bombing on the first value above because it thinks it's a number...
 

NJDude

Expert
Licensed User
Longtime User
It seems it gets confused with an HEX number or something when having an "E", the resulting value is always 7FFFFFFF.

If you do this you will see:
B4X:
...
 
Dim z AsString = "HE5001"
 
...
 
Msgbox("IsNumber " & Bit.ToHexString(z).ToUpperCase, "")

Among other values.

I don't know, just guessing.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It seems like a bug in the Android VM. The 'e' character causes the parser to treat the value as if it is written in exponent notation.

You can use this workaround:
B4X:
Sub IsNumber2(s As String) As Boolean
   If IsNumber(s) Then
     Dim d As Double = s
     Return d <> d + 1
   Else
     Return False
   End If
End Sub
 
Upvote 0
Top