toddjensen00 / vba-json

Automatically exported from code.google.com/p/vba-json
0 stars 0 forks source link

improve parseNumber() with Long number #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
  1. Set json = lib.parse("{"BigNumber":32769}")
  2. an Exception was raise because the CInt Cannot process the Big number 

What is the expected output? What do you see instead?

  Debug.Assert json.Item("BigNumber") = 32769

What version of the product are you using? On what operating system?

Please provide any additional information below.

'I use CLng to replace CInt
Private Function parseNumber(ByRef str As String, ByRef index As Long)

    Dim value   As String
    Dim char    As String

    Call skipChar(str, index)
    Do While index > 0 And index <= Len(str)
        char = Mid(str, index, 1)
        If InStr("+-0123456789.eE", char) Then
            value = value & char
            index = index + 1
        Else
            If InStr(value, ".") Or InStr(value, "e") Or InStr(value, "E") 
Then
                parseNumber = CDbl(value)
            Else
                parseNumber = CLng(value) 'CInt(value)
            End If
            Exit Function
        End If
    Loop

End Function

Original issue reported on code.google.com by akun...@gmail.com on 9 May 2010 at 1:34

GoogleCodeExporter commented 9 years ago
This needs CDbl instead of CInt. Otherwise you can get numbers which are 
written as a single number but are too big for long. (because it's not written 
using scientific format, the check for "e" or "E" won't pick it up).

Original comment by djm...@googlemail.com on 27 Aug 2012 at 10:05