Solved

compatible files

Posted on 2002-06-10
4
139 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
Restricting text box entry from \/:?<>"| 9 77
VBS file using code from 2nd file (txt or vbs) 4 32
How to make an ADE file by code? 11 81
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now