Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Binary File Access

Posted on 1998-11-01
2
Medium Priority
?
166 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses

972 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