Solved

Binary File Access

Posted on 1998-11-01
2
147 Views
Last Modified: 2010-04-30
I have a binary file that I need to open. Each record is 80 bytes in length. I need to open this file with VB5.0, convert each record into a string and parse out the data in each record. Can you please suggest some code to get me started on the right track, especially how to get the binary file record into a string that I can parse?
Thanks
0
Comment
Question by:gcassel
2 Comments
 
LVL 2

Accepted Solution

by:
lmorris earned 100 total points
ID: 1442783
Here's an example program. You'll need to read up on type statements, FreeFile(), open command, put/get, eof.


Option Explicit

Private Type Record
    LastName As String * 15
    FirstName As String * 15
    EMail As String * 30
    Comment As String * 20
End Type

Private Sub Form_Load()
    'Create a file so we can later read it back.
    Dim lFileHandle As Long
    lFileHandle = FreeFile()
   
    Open "C:\Temp\Test.dat" For Binary As #lFileHandle Len = 80
   
    Dim tRecord As Record
   
    tRecord.FirstName = "Larry"
    tRecord.LastName = "Morris"
    tRecord.EMail = "lmorris@netins.net"
    tRecord.Comment = ""
   
    Put #lFileHandle, 1, tRecord
    Close #lFileHandle
   
   
    'Read back the record
    lFileHandle = FreeFile()
    Open "C:\Temp\Test.dat" For Binary As #lFileHandle Len = 80
   
    Dim lRecordCount As Long
    lRecordCount = LOF(lFileHandle) / 80
   
    Dim l As Long
    For l = 1 To lRecordCount
        Get #lFileHandle, l, tRecord
       
        Debug.Print Trim(tRecord.LastName) & ", " & Trim(tRecord.FirstName)
        Debug.Print Trim(tRecord.EMail)
        Debug.Print Trim(tRecord.Comment)
    Next l
   
    Close #lFileHandle
End Sub

0
 

Expert Comment

by:newmembername
ID: 3410510
use "type [name]" and write/read using random access
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restricting text box entry from \/:?<>"| 9 86
How to create a duplicate finder Application 9 120
Copy a row 12 61
Hide vba in gp 7 93
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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