Solved

Binary File Access

Posted on 1998-11-01
2
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 6 hours left to enroll

622 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