Convert ByteArray to Double variable.

I'm using WinSock control in VB6. The app receives an array of bytes with
two double definition (Event DataArrival).

How can i convert this Byte-Array to a Double variable?

Here is the first double definition array:

The double number is 12.86
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

'like this
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
        (ByVal Destination As Long, _
        ByVal Source As Long, _
        ByVal Length As Long)

Sub Main()
Dim coord(0 To 7) As Byte
Dim dbl As Double
coord(0) = 184
coord(1) = 30
coord(2) = 133
coord(3) = 235
coord(4) = 81
coord(5) = 184
coord(6) = 41
coord(7) = 64

Call CopyMemory(VarPtr(dbl), VarPtr(coord(0)), 8)
Debug.Print dbl
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

PS - I guess that if you get multiple doubles this way (say 2) to can get subsequent doubles by adding 8?

Dim coord(0 To 15) As Byte
Dim dbl1 As Double
Dim dbl2 As Double

coord(0) = 184
coord(1) = 30
coord(2) = 133
coord(3) = 235
coord(4) = 81
coord(5) = 184
coord(6) = 41
coord(7) = 64
coord(8) = 184
coord(9) = 30
coord(10) = 133
coord(11) = 235
coord(12) = 81
coord(13) = 184
coord(14) = 41
coord(15) = 64

Call CopyMemory(VarPtr(dbl1), VarPtr(coord(0)), 8)
Call CopyMemory(VarPtr(dbl2), VarPtr(coord(8)), 8)
Debug.Print dbl1
Debug.Print dbl2
CarlosRodriguesAuthor Commented:
Thanks. Your answer solves my problem but, can´t VB do that for me?
Try this code.

dim someText as string
dim varByte() as Byte
dim someTextConvertAutomatic as string



'Visual Basic converts this variable automaticaly. How can i do this to a Double variable

someTextConvertAutomatic = varByte
debug.print someTextConvertAutomatic
Carlos, I'm afraid you can't. The developers of VB, whatever their motivation might be, decided to incorporate the bytearray to string conversion (and vice versa) in the VB language, but it really is an exception to the rule. Generally it is impossible to do stuff like this in native VB.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.