Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to read data from binary file? | Excel Programming | |||
Read Binary | Excel Programming | |||
Solver returns non binary answer in binary constrained cells | Excel Worksheet Functions | |||
read a Unix binary file | Excel Programming | |||
How can I read/write file with binary format??? | Excel Programming |