Re: Working with floating point numbers.



Hi Andrew,

A few disconnected thoughts:

Some languages let you do this sort of thing by declaring two variables
at the same address - e.g. a Double and an 8-byte array of Char. You can
then write your 8-byte slice into the array variable and immediately
retrieve the Double value from the Double variable.

VBA offers a very restricted version of this: you declare two custom
Types containing the variable types you need, and can then use the
obscure LSet statement to map one to the other. E.g.:

Type MyFloats
S As Single
D As Double
End Type
Type MyStrings
S As String * 4
D As String * 8
End Type

Sub Test32()
Dim F As MyFloats
Dim S As MyStrings
Dim ArBytes(3) As Byte

'Bytes are C2 ED 40 00, but must reverse order!
ArBytes(0) = &H0
ArBytes(1) = &H40
ArBytes(2) = &HED
ArBytes(3) = &HC2

S.S = ArBytes()
LSet F = S
Debug.Print F.S

End Sub

Alternatively, if it fits your workflow, you might consider
preprocessing your input with a Perl script that uses the powerful
unpack() function to convert your sequence of bytes into decimal string
representations of the numbers of the binary numbers.




On Mon, 20 Feb 2006 02:51:26 -0800, InvestorDrew
<InvestorDrew@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi all,

I hope you don't mind me lauching straight into a question. Thanks for a
great forum, I have picked up a few good tips here! :)

Anyhow, here is my question:-
I am loading information from an array of bytes and then immediately storing
the information. In this information are bytes sequences representing Single
(4 bytes) and Double (8 byte) values. I wish to avoid calculating the
floating point numbers only to immediately save them and not use them.

For instance I know the four hexidecimal bytes C2 ED 40 00 represents
-118.625 but I just want to save the bytes into a double field. Now when I
try to use the CDbl("&HC2ED4000") functionI only get the number as an integer
rather than the floating point. Can anybody help with a sugestion?

Also in the future I thiink that I'll have to reverse the situation and
convert a double to a string of hexideciamal numbers. I am sure the internals
of Access must do this stuff all the time but I am just ignorant of how to
access the functionality.

Any help would be much appreciated,

Cheers and Happy Presidents day to our US buddies!,
Andrew
Australia

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.

.



Relevant Pages

  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Structure conversion from C++ to VB-2008?
    ... Public Structure AmiVar ... Dim type As Integer ... Public *array as Single ... Public *string as String ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structures conversion from C++ to VB-2008
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)

Loading