LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Read Binary Database File

Can anyone provide me with sample/psuedo code for reading a binary
file using VBA. I know about using open and input functions for
reading files in general, but mostly having trouble getting the data
in to a format I can work with in VBA. The data is written in a C
program with the records one after another in the following format
(struct is like type or class in VBA):

typedef struct
{
char del;
char company[41];
char street1[46];
char street2[46];
char city[25];
char state[3];
char zip[17];
char phone[21];
char email[91];
long namenum;
char buf[53];
char lock;
} PhoneDataStruct;

The structure is byte-packed in C, which means the fields don't start
on any special byte boundries, each file just comes right after the
next in the file. So for example:

The first byte of each record is one byte, a 0 for not-deleted, and
non-zero for deleted. The 2nd byte is the start of the Company
(company name) field, and the next 41 bytes make up the company name.
Somewhere within those 41 bytes is a zero byte which marks the end of
the null-terminated string.

Sorry if this is obvious to you, but for those who have never used C,
the idea of a struct and fixed-length null-terminated data may be
foreign.

All I want to do is read the entire file, one record at a time, and
dump the field in to cells in a spreadsheet... I know how to do
everything except put the data in to VBA strings so I can work with
them. The i/o function input() just returns a variant with the 1024
bytes of data that make up each record (I didn't include the full
struct above)... but then how do I get those 1024 bytes of data in to
individual strings for each field?

I could just write something in C, sure, but I'm trying to provide a
script in VBA only that I can give to a client so they can read my
data file and work with it in Excel. I could give them a COM object
or something else they could call... but I don't wanna =]
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read data from binary file? Valery Excel Programming 4 July 21st 08 04:59 PM
Read Binary Dan Excel Programming 4 October 13th 05 04:42 PM
Solver returns non binary answer in binary constrained cells Navy Student Excel Worksheet Functions 6 September 1st 05 03:11 PM
read a Unix binary file Arnaud Boëlle Excel Programming 2 April 20th 05 09:24 PM
How can I read/write file with binary format??? NC Excel Programming 2 May 27th 04 09:35 AM


All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"