August 25th, 2004, 08:30 PM
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!
//-----Begin Matlab Script (read_da.m)---------------
% READ_DA -- read NIR NSAS data files.
% 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.
[fn,pt]=uigetfile('*.da','Select NSAS *.da file');
fn = fullfile(pt,fn);
% loop for reading sample names
spl_name(nspec,1:30)=[setstr(k(5:14))' sprintf(' %2g:%2g:%2g %2g-%2g-%4g',hr,mi,se,mo,da,yr)];
//-----End Matlab Script (read_da.m)-----------------