This came up in another thread, and I wouldn't mind having a solution for my own VB6 library.

Let's say we have an ASCII file with numeric data in it that we know how to parse. For example purposes, we'll just say that the following was read out of this ASCII file:

Code:

    Dim bb() As Byte
    ReDim bb(5)

    bb(0) = Asc("9")
    bb(1) = Asc("8")
    bb(2) = Asc("7")
    bb(3) = Asc(".")
    bb(4) = Asc("5")
    bb(5) = Asc("6")
And now, I'd like to convert that into a Single and/or Double.

Sure, here's one way to do it:

Code:

    Dim d As Double

    d = CDbl(StrConv(bb, vbUnicode))
    Debug.Print d
But that's jumping through quite a few hoops to do it:
* Converting the byte array to a String:
* Allocate space for a BSTR.
* Take our bb array and convert it from ASCII to 2-byte Unicode characters.
* Then do the conversion.

It just seems like there should be a way to take VarPtr(bb(0)) and feed that directly into some API call that returns our floating point number. (Maybe adding a vbNullChar to the end of our bb array, to make it a c-style ASCII string.)

Within the msvbvm60.dll library, I see functions named as follows:
  • __vbaFpCDblR4
  • __vbaFpCDblR8
  • __vbaFpCSngR4
  • __vbaFpCSngR8
  • rtcR8ValFromBstr

It just seems that one of those might get this job done, but I can find no documentation nor usage of any of those functions.

Or maybe there's an API call in another library that'll get it done.

Any ideas?