Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Binary File Access

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

Independent Software Vendors: 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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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

670 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