Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Read One byte at a time

Posted on 2006-04-19
1
Medium Priority
?
262 Views
Last Modified: 2010-05-01
I want to analyze a file one character at a time, one byte at a time. What is the most efficient way of doing this? Should I read it from the drive one byte at a time, or read a big chunk and then loop through the chunk one byte at a time? And if reading a big chunk is the best way, what the most efficient way of looping through the chunk one byte at a time?

Rich
0
Comment
Question by:rcherne1
1 Comment
 
LVL 8

Accepted Solution

by:
Leo Eikelman earned 800 total points
ID: 16490963
If you wanted to read one byte at a time this is efficient:


Public Sub ReadFileByByte(ByVal FileName As String)
    Dim lngFileNum As Long
    Dim lngByteNum As Long
    Dim lngFileSize As Long
    Dim bytData As Byte

    'get next available file number
    lngFileNum = FreeFile()
    'open the file
    Open FileName For Binary As #lngFileNum
    'Get the file size
    lngFileSize = LOF(lngFileNum)

    'loop throu each byte of the file
    For lngByteNum = 1 to lngFileSize
        'read the bye at position lngByteNum
        Get #lngFileNum, lngByteNum, bytData

        'do something with the byte

    Next 'lngByteNum
    'close the file
    Close #lngFileNum
End Sub


Cheers,

Leo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses

810 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