Re: IsNumeric not returning correctly



This is a special case. IsNumeric will correctly interpret scientific
notation, or VB's version of it, so 1E6 gets interpreted as 1,000,000 (1 *
10 ^ 6). Since that's numeric, IsNumeric returns True.

The only way I can think of to get around this is to do something like this:

Private Function IsReallyNumeric(ByVal s as String)
IsReallyNumeric = IsNumeric(Replace(s,"e","z"))
End Function



Rob

"Nathan Truhan" <ntruhan@xxxxxxxxxxxxx> wrote in message
news:CD1B59E2-B2D8-4524-AAA1-DB0EA4FC83E4@xxxxxxxxxxxxxxxx
All,

I think I may have uncovered a bug in the IsNumeric function.
I am writing a Schedule Of Classes Application for our campus and have a
seciton that lists the Times, Buildings and rooms for courses.

In this section I check if the value is numeric so I can strip off leading
0's on rooms to make it more readable. if I specify it.

The function looks like:
Private Function IsNumeric2(ByVal sString) As Boolean
If Len(sString) = 0 Then Return False

Dim bNumber As Boolean = True
Dim iInt As Integer
For iInt = 1 To Len(sString)
bNumber = bNumber And IsNumeric(Mid(sString, iInt, 1))
If bNumber = False Then Exit For
Next

Return bNumber
End Function

And performs the IsNumeric on each character in the string and bails if it
is false early. this fixes the bug so that 0E200 returns false like I and
possibly others would.
Private Function PaddCell(ByVal sValue As String, ByVal PaddCount
As
String, Optional ByVal StripNumeric As Boolean = False) As String
Dim tString As String = sValue
If StripNumeric And IsNumeric(tString) Then
tString = CStr(CInt(tString))
While Left(tString, 1) = "0"
tString = Mid(tString, 2)
End While
End If
Dim i As Integer = Len(tString)
Dim j As Integer
For j = i + 1 To PaddCount
tString += " "
Next
Return tString
End Function


the problem I have found is that if I have a room that starts with #E##,
where # is a number, such as 0E202, 1E100, or 0E500, IsNumeric returns
this
value as true!. I have tested this in .NET 2.0. I am not sure if it
occurs
in 1.1. To work around the problem, I had to write a function, which I
call
IsNumeric2:

Was this a known bug somewhere that I missed, or is this a special case I
may not be aware of. Note in the PaddCell function, the tString is being
passed as a string value, not numeric so IsNumeric should treat it as a
string I would think and not something in Scientific Notation, which is
the
only use of E I could think of.

Thanks,
Nathan


.



Relevant Pages

  • Re: help to a very special split
    ... 'Will split a string on the change from number to non-number and vice versa ... Dim i As Long ... Dim bNumber As Boolean ...
    (microsoft.public.excel.programming)
  • Re: IsNumeric not returning correctly
    ... Dim bNumber As Boolean = True ... Dim iInt As Integer ... Private Function PaddCell(ByVal sValue As String, ... Dim tString As String = sValue ...
    (microsoft.public.vb.bugs)
  • RE: IsNumeric Bug or misunderstanding?
    ... Private Function PaddCell(ByVal sValue As String, ... Dim tString As String = sValue ... Dim i As Integer = Len ... Dim bNumber As Boolean = True ...
    (microsoft.public.dotnet.languages.vb)
  • Re: IsNumeric Bug or misunderstanding?
    ... Private Function PaddCell(ByVal sValue As String, ... Dim tString As String = sValue ... Dim i As Integer = Len ... Dim bNumber As Boolean = True ...
    (microsoft.public.dotnet.languages.vb)
  • IsNumeric Bug or misunderstanding?
    ... Private Function PaddCell(ByVal sValue As String, ... Dim tString As String = sValue ... to write a function, which I call IsNumeric2, which does a for loop on each ... Dim bNumber As Boolean = True ...
    (microsoft.public.dotnet.languages.vb)

Loading