Solved

compatible files

Posted on 2002-06-10
4
140 Views
Last Modified: 2012-05-04
I need to have visual basic 6.0 write and read a binary file that can also be read be a c program.
Can anyone provide me with a simple example?
Need to write strings, a character,floating point number, and a structure.

Thanks
0
Comment
Question by:pentomino
  • 2
4 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 7067658
Here is an example of reading/writing a binary file.  I have not looked at the code, but it may be helpful.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=14583&lngWId=1
0
 
LVL 22

Accepted Solution

by:
rspahitz earned 100 total points
ID: 7067835
VB can write "binary" files by simply encoding the pieces any way you want.  Then C can read those by unencoding from the same process.

Are you looking for a specific predefined format, like packed decimal or "zip" format?

To write data from VB:

strXXX = "testing"
chrX="@"
dblXXX=3.14159
open "somefile.bin" for output as #1
print #1, strXXX; chrX; dblXXX;
close #1

' resulting file:
somefile.bin
------------
testing@3.14159

Obviously, the extraction will not work well unless you know the length of the string and maybe the type of data, so you would probably want to add something like this:

print #1, chr$(len(strXXX));strXXX;

On the C-end, it would need to understand the style using a mapping mechanism.  It may just be simpler to create an ActiveX control to do all the work and add methods for "CreateFile", "AddItem", "GetItem", etc.
0
 
LVL 1

Author Comment

by:pentomino
ID: 7067876
rspahitz

Well, I was hoping I would not have to tweak the C code at all.  If I have to modify how it reads the data, I just may go with a text file.

Pentomino
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7068243
Well, then, find out the format that C is using and write VB code to put it in that format.  I haven't checked out gencross' link, btu maybe that will handle it or get you close.

The only caveat I can see is that the data format may change depending on the O/S.  For example, a 32-bit O/S may write a number as 4 bytes, but a 64-bit O/S may write the same number with 4 additional bytes with all zeros.  This would cause some incompatibility and require some sort of upgrade tool for "old" files being moved to the new O/S.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question