1

I have hunted about quite a bit but can't find a way to get at the Hexadecimal or Binary representation of the content of a Double variable in VB6. (Are Double variables held in IEEE754 format?)

The provided Hex(x) function is no good because it integerizes its input first. So if I want to see the exact bit pattern produced by Atn(1), Hex(Atn(1)) does NOT produce it.

I'm trying to build a mathematical function containing If clauses. I want to be able to see that the values returned on either side of these boundaries are, as closely as possible, in line.

Any suggestions?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Wojja62
  • 76
  • 5
  • Can the debugger not reveal this? (I don't have VB6 installed because it is from ancient times) – Lightness Races in Orbit Dec 21 '19 at 20:14
  • Similar thing for .NET that may be possible/available in VB6: https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/troubleshooting-data-types. Not the binary representation but if you're only doing mathsy stuff then you _probably_ don't need that, you just need all the precision of the type – Lightness Races in Orbit Dec 21 '19 at 20:17

1 Answers1

3

Yes, VB6 uses standard IEEE format for Double. One way to get what you want without resorting to memcpy() tricks is to use two UDTs. The first would contain one Double, the second a static array of 8 Byte. LSet the one containing the Double into the one containing the Byte array. Then you can examine each Byte from the Double one by one.

If you need to see code let us know.

[edit]

At the module level:

Private byte_result() As Byte

Private Type double_t
    dbl As Double
End Type

Private Type bytes_t
    byts(1 To 8) As Byte
End Type

Then:

Function DoubleToBytes (aDouble As Double) As Byte()
   Dim d As double_t
   Dim b As bytes_t
   d.dbl = aDouble
   LSet b = d
   DoubleToBytes = b.byts
End Function

To use it:

Dim Indx As Long

byte_result = DoubleToBytes(12345.6789#)

For Indx = 1 To 8
   Debug.Print Hex$(byte_result(Indx)),
Next

This is air code but it should give you the idea.

Jim Mack
  • 1,070
  • 1
  • 7
  • 16
  • Dear Jim, You are way ahead of me!! :-) What is a "UDT"? Would you be able to fill in the code for some such function at the following:- Public Function DoubleToHex(ByVal D as Double) as String .... DoubleToHex = ... ' The magic!! :-) End Function ' DoubleToHex – Wojja62 Dec 22 '19 at 12:54
  • @Wojja62 - I know this isn't exactly what you asked for but it can serve as an example of how to do it. – Jim Mack Dec 22 '19 at 13:23
  • UDT: User Defined Type. @JimMack: Great idea. I now remember again, why I liked VB6 so much, and still sad that M$ killed it with the "VB".NET. – nabuchodonossor Dec 23 '19 at 08:44