Convert Byte Array to Double.
Author Message
Convert Byte Array to Double.

Haya -

Does anyone have a good idea how to convert a Byte array to a Double?  I can
go the other way using LSet but I can't get that to work in this case

(The Type with the byte has to be the assignee otherwise it give a Type
mismatch).

Tue, 12 Mar 2002 03:00:00 GMT
Convert Byte Array to Double.

You can use the Windows API CopyMemory function.  The code below copies a double
to a byte array and back to another double.

John.......

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination
As Any, Source As Any, ByVal Length As Long)

Dim ab() As Byte
Dim d1 As Double, d2 As Double
Dim i As Integer

d1 = 1234.56
ReDim ab(7)
Call CopyMemory(ab(0), d1, 8)

For i = 0 To 7
Debug.Print ab(i)
Next

Call CopyMemory(d2, ab(0), 8)

Debug.Print d2

Quote:

> Haya -

> Does anyone have a good idea how to convert a Byte array to a Double?  I can
> go the other way using LSet but I can't get that to work in this case

> (The Type with the byte has to be the assignee otherwise it give a Type
> mismatch).

Tue, 12 Mar 2002 03:00:00 GMT
Convert Byte Array to Double.
Got it.  Thanks

Quote:

> You can use the Windows API CopyMemory function.  The code below copies a
double
> to a byte array and back to another double.

> John.......

> Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(Destination
> As Any, Source As Any, ByVal Length As Long)

>     Dim ab() As Byte
>     Dim d1 As Double, d2 As Double
>     Dim i As Integer

>     d1 = 1234.56
>     ReDim ab(7)
>     Call CopyMemory(ab(0), d1, 8)

>     For i = 0 To 7
>         Debug.Print ab(i)
>     Next

>     Call CopyMemory(d2, ab(0), 8)

>     Debug.Print d2

> > Haya -

> > Does anyone have a good idea how to convert a Byte array to a Double?  I
can
> > go the other way using LSet but I can't get that to work in this case

> > (The Type with the byte has to be the assignee otherwise it give a Type
> > mismatch).