Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading a double from a file
Message
From
01/05/1998 06:54:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
01/05/1998 00:33:24
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00096119
Message ID:
00096227
Views:
11
>The best solution I can see right now: write a very small dll (in C or C++) with only one function. The function should look like this:
>
>
void Convert(LPCSTR tpszDestString, LPCSTR tpszSourceString, int tnLength)
>{
>   float lnAFloat;
>   double lnADouble;
>
>   //-- Copy the contents of the source string
>   //   other the destination number.
>   //   This will "convert" to numeric...
>   //-- Write the number as string into the dest buffer.
>   if (tnLength == 4)
>   {
>      memcpy((void*)&lnAFloat, (void*)tpszSourceString, 4);
>      sprintf(tpszDestString, "%f\0", lnAFloat);
>   }
>   else
>   {
>      memcpy((void*)&lnADouble, (void*)tpszSourceString, 8);
>      sprintf(tpszDestString, "%f\0", lnADouble);
>   }
>}
>
>I haven't tested this code, but it should work... maybe with some bug fixes... :)
>
>Vlad
>
>>Hello!
>> I'm using low level functions to read (import) a binary file (I think it was created with C/C++). Of course, every thing I read becomes a character. Is there an easy way (I mean a function or something like that) to "cast" a 4-byte character to a VFP Flotant point variable, and a 8-byte to Double?
>> I can do the "translation" step by step (I mean bit by bit) in VFP, but it takes too long, considering that I have to do 60,000 or so "interpretation" of this every time I read the file.
>>
>> TIA.
>>
>>Ing. Omar Zavala
Maybe I'm missing something but wouldn't it be something like this :
nValue = 0
for ix=1 to nBytes
  nValue = nValue + asc(substr(cString,ix))*256^(ix-1)
endfor
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform