Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




VB6: How To Read Data From Binary File In IEEE Floating Point, Little-Endian Format?


I have a proprietary binary file here that contains a variable called 'Hydroxyl #', seven sample titles (2, 5, 9, 12, 20, 23, 31 - these titles could just as easily be text, so they are probably stored as strings), and the associated float values for the variable (44.94, 46.17, 51.93, 54.08, 61.62, 63.75, 84.77). I have attached the zipped data file in 'Polyvl.zip'.

Below, I have also pasted a Matlab script that a long-since departed member of our company wrote to read the file. The script uses the 'fopen' command with the 'ieee-le' option (IEEE Float-Point, Little-Endian, bits not explicity specified).

My question is, how do I properly read (and also, display) this data properly in Visual Basic 6? I am currently using the 'Open ... For Binary Access Read ...' statement and the 'Input' statement to read the data into a Variant type variable. I am able to grab some of the data (Hydroxl #), but the rest looks like garbage.

Contact me at DSanborn3@hotmail, or DSanborn3 (at AIM, MSN, Yahoo) with additional questions or comments. TIA!

Regards,

Daniel

//-----Begin Matlab Script (read_da.m)---------------

function [a,spl_name]=read_da(fn);
% READ_DA -- read NIR NSAS data files.
%
% [a,spl_name]=read_da('filename');
% or
% [a,spl_name]=read_da;
%
% Will not work for full Vis/NIR range.
% Works for spectra transferred from pc to rs/6000 via binary ftp.
%
% See read_fda for reading full Vis/NIR range.

if nargin==0,
[fn,pt]=uigetfile('*.da','Select NSAS *.da file');
fn = fullfile(pt,fn);
end

inp=fopen(fn,'r','ieee-le');

nspec=0;
k=fread(inp,128,'char');

fseek(inp,2944,-1);
%
% loop for reading sample names
%
while ~feof(inp)
nspec=nspec+1;
da=k(65)+k(66)*256;
mo=k(67)+k(68)*256;
yr=k(69)+k(70)*256;
hr=k(71)+k(72)*256;
mi=k(73)+k(74)*256;
se=k(75)+k(76)*256;
spl_name(nspec,1:30)=[setstr(k(5:14))' sprintf(' %2g:%2g:%2g %2g-%2g-%4g',hr,mi,se,mo,da,yr)];
k=fread(inp,128,'char');
fseek(inp,(nspec+1)*2944,-1);
end;

frewind(inp);
a=zeros(nspec,700);
for i=1:nspec
k=fread(inp,2944./4,'float');

a(i,=k(33:732)';
end;
fclose(inp);

//-----End Matlab Script (read_da.m)-----------------




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
IEEE Format For FLoating Point Calculations
hii,
how can i convert Text1.Text to Floating Variable using IEEE-754 Floating Point Conversion,
is there any ready made function?
Yogi

Reading Floating Point Data From A Binary File
Hi Gurus, I need some help.

I am reading some floaing point data from a Binary file using GET Statement.

VB has "Single" data type which is defined as a IEEE 32-bit (4-byte) floating-point number. So, when I use "Get" from a byte position using a "Single" data type variable, I get 4 bytes, and there is no drama.

Unfortunately, I have to write the program in a language (MapBasic) which does not support "Single" data type. It supports "Float" which is 8-byte. Hence when I use the "Get" statement with a Float variable, instead of getting 4 bytes, it gets 8 bytes and gives me a number which is not the number I am looking for.

Is there any way I can solve this problem.

Thanks guys for your attention.

To Transform IEEE-P 754 80-bit Floating Point
Hallo experts!

I import the 80bits as string to VB. Is there a routine/function to transform the values to VB type "double". (of course by loss of precision) and vis versa.

Thanks and regards

Hans

Convert Bytes To IEEE-754 Floating Point
I have 4 ordered bytes values (0-255) which I receive from a device's output. These 4 bytes represent a 32bit floating point value in IEEE-754 format. I need a VB6 function which converts the 4 bytes into this value. Thanks in advance.

Single And Double Data Type Floating-point Format
The range of the single data type is quoted in VB help as +/-3.402823e38 with a zero gap of +/-1.401298e-45. Similarly the double data type has a range of +/-1.79769313486231e308 and a zero gap of +/-4.94065645841247e-324.
I am aware of the IEEE754 32-bit standard with its sign bit, 8-bit exponent, implied one bit and binary point followed by a 23 bit fraction for single data types and similar 64-bit standard double data type with an 11-bit exponent and 52-bit fraction.
I am a part time lecturer on BND Computer Processes which covers binary systems. One of my students has asked me to demonstrate how to calculate the ranges for VB data types and I have done this for all data types except Single and Double. Does VB use a different format? Any suggestions?

 

Converting Microsoft Binary Format To IEEE Format Using VB 6
I wrote an accounting package back in the late 80's, early 90's that began back with GWbasic and so on upto Professional Development System ver 7.10. All the Data that was saved to random accessed files using the old unsupported Microsoft Binary Format (MBF). 10 years later the firm now wants me to develop a windows version of the software. I've come to a snag in development right from the start where MS VB no longer supports the MBF format. There are 3 function I need, they are CVI (integer), CVS (single), CVD (Double), these convert MBF strings to thier respected ieee Decimal format. I've been searching the net for about a week trying to find a method to do this and have come up against a brick wall. if anyone is able to assist me in my problem please feel free to add your advice. Anything is better than what I've come up with so far.

Thanks
Russ

Convert MB Binary Format Number To IEEE
Quick basic has a function CVSMBF to convert the old MS Binary format numbers to IEEE format numbers.


eg CVSMBF(highdata$)
The output being a single precision number eg 4.28
highdata$ being a 4byte string

I am coverting an old QB program to VB5

Sorry OnErrOr my previous query was missleading, what I really need is an answer to the above.

Data Types: Double And Floating Point
Hey guys,I was wondering is there any other vairable type to hold a fractional number other then Double?And what does "floating point" mean?Also what is "fixed point" then?
Thanks in advance,
Misha

(RESOLVED)Wat Data Type Can Represent Character And Floating Point?
I wish to have a data type which could represent both character and floating point?
How?

DIM A AS VARIANT?

Simple Math Using The Double-precision Floating-point Data Type
I'm just learning how to program using VB 6.0. I've built a calculator. Whenever numbers are entered (using either the keyboard or on-sceen buttons I've created), they appear in a label which serves as the display screen for the calculator. I'd like it to be capabale of dealing with large numbers, so I've declared all of my variables as double-precision floating-point data. The program is near finished and most mathematical functions seem to work quite well (adding, subtracting, dividing, multiplying, exponents, square roots, etc.) But for some strange reason, when I enter "650.2 - 650" (or 650.0), and hit the "=" key, I get 0.200000000000045. It not only appears in my display window, but even when I put a breakpoint next to the line of code that performs the operation and hover over each variable, the function looks like this: "0.200000000000045 = 650.2 - 650". So it doesn't seem to be an error with the manner in which I'm displaying the information, nor the way in which I'm transfering it to the display screen. It seems that the mathematical computation is actually a tiny bit inaccurate. Is that simply a negative characteristic of using double data types or is there something else that explains this occurrence? Should I be using another data type? If you need to, I can certainly include the code, but like I said, I think this has something to do with the way it's storing the variables, not my code. Thanks in advance for your help...

- Matt -

How To Read Binary Data From A File
i want to read data from *.SD5 file...the data in that file is stored in binary formate...i want to read all the data from that file
in string or text formate.......how to do that............i used the following code...but i get some junk...

Private Sub Command1_Click()

Dim MyString, MyNumber
Open App.Path & "sarsewa2sarangarh.sd5" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, MyString, MyNumber ' Read data into two variables.
MsgBox MyString & MyNumber ' Print data to the Immediate window.
Loop
Close #1 ' Close file.

End Sub

How To Read Binary Data From INI File
Hi All,

Can anyboady tell me how to read binary data from INI file ?

As in my ini file I am storing a string which may have all possible ascii value (including '/n'..'/r'...and all other except 0 i.e. null ).
When I read it using GetPrivateProfileString then it's not able to read all these special characters ...

Thanks,
-Yogendrasinh

How To Read Binary Data From A File
I have a prob in reading data from specified position from a binary file

This is my probs..

I am writing data in a file opening in binary write mode in 5000 and 15000 positions using put statement

Data in 5000 position is "15000"
Data in 15000 position is "Test this"

So now when i tried to read data from that file using get statement it is not giving me the correct data for me , so let me know what is the probs
If any one has code let me know that , it is urgent

Thanks

How To Read/write Binary Data To A File
Hi all,

How do I read/write binary data to/from a file. I dont want the user toopen the file in notepad/wordpad and read the contents

Regards,
MRL

URGENT: How Do You Read In A Binary Data File?
How do you read in a binary data file and save it into an array of records?

I have the basic code for opening a file for input

open "test.dat" for binary As #1

get #1, , EmpDB

get #1, , Current

get #1, , Counter

close #1


and


open "test.dat" for binary As #1

put #1, , EmpDB

put #1, , Current

put #1, , Counter

close #1


but every time I access it, the data that I saved is not there!

any help would be apprciated it!

Read Image From A Binary File Of Data And Images?
I am ensnarled in a requirement for a VB6 application that will read (and write) a binary file that contains some data and an image.

I can handle the data using get and put commands but I don't know how to handle the image.

In VB.NET I could use a file stream to load the data into a memory stream and use the Image FromStream method to load the image from the memory stream as shown in the extract below:

Dim tS As System.IO.Stream = File.Open(fileName, FileMode.Open, FileAccess.Read)
Dim tsIn As New BinaryReader(tS)
Dim continue As Boolean = True

If continue Then
Dim ms As New MemoryStream
ms = New MemoryStream(tS.Length)
ImageArrayByte = ms.GetBuffer()

Dim CurrentPosition As Long = tS.Seek(0, SeekOrigin.Current)

tsIn.Read(ImageArrayByte, 0, tS.Length - CurrentPosition)
ms.Write(ImageArrayByte, 0, ImageArrayByte.Length)

Dim tempBmp As Image = Image.FromStream(ms)

The only relevant method I found in VB6, however, is something like
Picture1.Picture = LoadPicture("file name")
that expects the file to only contain an image.

Is there a way for VB6 to load an image from a specified location in a binary file or must I delve into GDI+ or Windows API? (If so, are there any tutorials or examples for those APIs?)

Thanks,

Write Text Data To A Binary File (Also Read It Back)
Hey all.

Ii have an app that uses an array to hold text data (many reasons for this, but it is the way it is).

In any case, I encrypt the data using an AES_Rijndael Block Cipher, all is well.

I would now like to write this data to a BINARY file (I cannot do so to a text file as part of the encrypted data may contain the vbCRLF char set).

Ii need to also be able to read thebinary data back into my app, then populate an array with the DECRYPTED data (I have the encryption and decryption routines already working).

How can one do this?

Thanks.

Writing Text Data To A Binary File (and Read It Back)
Hey all.

I have an app that uses an array to hold text data (many reasons for this, but it is the way it is).

In any case, I encrypt the data using an AES_Rijndael Block Cipher, all is well.

I would now like to write this data to a BINARY file (I cannot do so to a text file as part of the encrypted data may contain the vbCRLF char set).

Ii need to also be able to read the binary data back into my app, then populate an array with the DECRYPTED data (I have the encryption and decryption routines already working).

How can one do this?

Thanks.

Read & Write Rtf Files In Binary Format
How to read rtf file in binary format and How to write binary contents to a rtf file?

Is It Possible To Extract Data From Point A To Point B In A Report (txt File)
hi,

I have a report that some one has given me but the only section i want is half way down and never in the same place and the same size.

whats the best way to extract this section to a new file.

if anyone can supply some code i would appeciate it

Beyond Floating Point
I have a 'program' written in Excel that uses cell formulas to come up with an answer. In itself, it isn't that exciting, the thing is that there are about 16000 rows and 50 some odd columns. Needless to say it takes a while to calculate. I have converted this to Visual Basic, however I get different answers, generally a couple of percent off. I think this may be because Excel stores 30 digits wheras VB only has 15. Is there any way I can store 30 digits in VB. If not, what language would you suggest I use that could handle this. Thanx.

Grover

IEEE Single ==> DEC Spfp Format
Does anyone have a function that converts IEEE single to DEC spfp format? Thank you.

Floating Point Numbers
I have a binary file containing vertex data. I need to read this information from the file as a 32 bit float for each x, y, and z position. No matter what I declare the variables I'm storing this information into, the program constantly returns the values as a Double.

Is there a way to do this in VB?

All help is greatly appreciated,

SoDA

String To Floating Point
Is there an easy way to convert a string = "3,5" to the floating point value 3,5 (or 3.5 for those outside of Norway?

Rounding Floating Point
how do you round single or doubles in visual basic?

Floating Point Variable To Hex Value
I am trying to show the hex values of a floating point number but having a problem.
My code:
Dim x As Single
x = CSng(Text1)
Label1 = Hex$(x)
Label2 = CSng("&h" & Label1)
If I enter 1.1 then label1 shows 1 and label2 shows 1
if I enter -1.1 then label1 shows FFFFFFFF and label2 shows 1
I searched the site and ran into the copymemory api and tried it but it crashed the program. I guess it couldn't move it to a label.
Is there a way to get the full hex value of a floating point variable?
Thanks in advance,

16-bit Floating Point Variables
Hi, does anyone know of a way to use 16-bit floating point variables/arrays in Visual Basic 6.0? I'm processing great amounts of data, so 32-bit floats are not an option (to memory intensive).

Perhaps there's a way to use integer variables/arrays to store it, but process them differently...

Floating Point Issues
I'm trying to work with a file that includes floating point information in 32 bit form. I need to read that information in and display it as a decimal number, allow the user to change that decimal number to another decimal number and then put it back into the file in 32bit form.

Getting it in and out of the file isn't a problem - I have it in a byte array , and once I've got it back into a byte array I don't have the slightest problem putting it back into the file.

So lets say that I have a 32 bit floating point number in a byte array as follows:
41 9E 66 66

Now I happen to know that converted to decimal that is 19.8; but I've no idea how to program a routine to make the change.

And equally, if my user enters "3" into a text box I have no idea how to turn that into the byte array 40 40 00 00.

Any help much appreciated,
Rob

Function To Cut The Floating Point Value
Hi, I am looking for the function that cuts the point in numbers.
EXAMPLE:

a = func("5.7")
a becomes 5

See what I mean, just want to cut the point in a real/floating point value.

I tried using an Integer but that just rounds it up (I do not want to do this)

3.9 becomes 4 (<-- NOT RIGHT)
3.9 becomes 3 (<-- RIGHT)

Thanks

Check Floating Point
I want to make an error checking to check whether the value in the textbox is a floating point or not. Please help me...........

How Can I Round A Floating Point In SQL ?
sql = "Select id, avg(delay) as avgdelay from tel group by id "

How can I make avgdelay a integer ?

Bytes To Floating Point
I want to convert 4 bytes in row to a single precision number. These are read from a file by means of Get commands but it's in big endian order so I must reverse them.

Specifically, I'd like to know if there is a similar function to ntohs and ntohl for single and double precision floating point numbers. Or is there any command to read a file backwards?

Floating Point Numbers
Admittedly this is a more general than just a vb-specific question: could someone give me a good address for a tutorial on floating point numbers, i.e. how single and double precision values are coded? I don't ask you guys to post an explanation as I guess it might take a good deal of writing.

Thanks in advance.

Floating Point Numbers
Anyone know where I can get some information on Floating Point Numbers?

Like: What are they?
What do you use them for?

Thanks

Floating Point Numbers
How can I get the user to enter a floating point number? If I use a text box then the val function, I believe errors occur.

Floating Point Error
Hi VB Programmers,

Here is my short code


Code:

Dim x as Double
Dim y as Double
Dim z as Double

x = 10.0005
y = 10.0004
z = x - y

MsgBox z


When I execute it, it show unexpected 9.9999999999759E-05.

How can I get the expected result such 0.0001?

Thank You.

Floating Point Number
How can i minimize the error if i have to work with floating point number.

Floating Point Numbers
Hello,

I would like to return the floating point remainder of a calculation and use it for further calculation

For instance 60000/256 = 234.375 I would like to strip the 375 and add it to a variable any help will be very much appreciated, and thanks in advance fo any replies.

8 Byte Floating Point Variable
Hello everyone im taking a class were we are doing some programming and basically our 1st program is a simple interest calculation program, but he said we need to have double precision 8 byte floating point variable. I have no idea how to do this in visual basic 6.0 can someone tell me how to set this up so that all my numbers are in this format, thanks so much. Im really new at VB

Floating Point Scientific Notation
Hi,
I'm designing a function shich returns a floating point value "single". how can I forca Visualbasic to print it normally without converting to the scientific notation.

MNT

Long 2 32bit Floating Point
I'm useing this bit of code to get values stored as 32bit floating point numbers in a file:

Private Sub Command1_Click()
Dim vals(3) As Long
Dim sngOut As Single
Dim lngIn As Long

vals(0) = Val("&H" & Text1.Text)
vals(1) = (Val("&H" & Text2.Text) * 256)
vals(2) = (Val("&H" & Text3.Text) * 65536)
vals(3) = (Val("&H" & Text4.Text) * 16777216)

Label1.Caption = vals(0) + vals(1) + vals(2) + vals(3)

lngIn = Label1.Caption
sngOut = 0
CopyMemory sngOut, lngIn, 4
Label2.Caption = sngOut

End Sub

It works fine for some values e.g the hex values 00,00,00,3F should retern 0.5 and they do, but some overflow the Long can anyone think of a way round this?

Floating Point Type Overflows
I'm writing a function that computes taxes, and when I input a number over 33,000 it gives me an overflow error. Obviously, it is because of the byte size of the datatype, but how do I allocate more memory for my double?

-Steve

Invalid Floating Point Operation
Hello,

I am experiencing a hard to catch error in my VB6 application. After running for several hours, it stops working correctly (but does not crash), also a messagebox pops up, titled VB6, with in it the text: "Invalid floating point operation".

I have no clue what might be causing this error, and it does not seem to be reproducable. I just happens, after some hours of running. No other application is active, the PC, running Win 98, is as clean as it can be.

Maybe anyone recognizes this kind of problem and have a solution?

Regards,
Bas

Hex To 32bit Floating Point Numbers
E02F = 703.5
4041 = 773
C04C = 847

How is this conversion done?
or how can this conversion be done in VB?

Floating Point Over A Serial Port
I would like to send single precision floating point numbers over the RS232 buss. There should be a way to do this directly by sending 4 bytesper number. Does anyone have any examples of this. I've seen the LSetinstruction used to move data between different data types on a byte bybyte basis if the types are the same size. This implies that a floatingpoint single precision number could be converted into 4 characters andthese characters then could be sent over the serial port. There areexamples athttp://support.microsoft.com/support/kb/articles/ Q235/8/56.ASP?LN=EN-U&SD=gn&FR=0&qry=floati ng%20point&rnk=12&src=DHCS_MSPSS_gn_SRCHSPR= VBB but I can't seem to get it to work in my applications.

Precision Of The Floating-point Types?
I need to find out the precision of the floating-point data types viz. Single, Double, and Decimal i.e. the maximum number of decimal digits ( i.e. base 10 digits ) that may be specified in thier literals. As this is not documented I thought I'd keep on enterring ever larger numbers in the Immediate Window until I got an overflow error and then count the number of digits. However to my frustration, as soon as I exceed 15 9' i.e. 9999999999999999, it gets converted to 1E+16.

How can I find out the precision and scale of these three data types?


8-byte Floating Point Number
Hi All,

If I have an 8-byte floating point number in hex how do I convert it to a
double?

0 0 0 0 0 98 C1 3F this should be about .13746

Thanks

Dan...

Single Floating Point Conversion
I'm trying to convert a 4-byte Hex value which supposed to be represented as a single floating point value under the IEEE 754. The following is what I did, but the result is not correct.

Dim test as Single
test = &HC2934000

test is eqaul to -1.030537E+09, but it suppose to be 1.150390625E+06 which is -73.625

Any help is greatly appreciated. Thanks!

Floating Point In MSHFlexGrid Control
Hi you all,
How do i set the floating point precision of a numeric field in the recordset of a MSHFlexGrid control. I am activating a query that rounds the value by 2 and still on the MSHFlexGrid control it shows as 3.4599999999999999 for example.
How do i fix it ?

Copyright © 2005-08 www.BigResource.com, All rights reserved