Solved

Binary File Access

Posted on 1998-11-01
2
145 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…
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…

760 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

22 Experts available now in Live!

Get 1:1 Help Now