Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read binary file

Status
Not open for further replies.

Per9922

IS-IT--Management
Oct 1, 2004
74
SE
Hello all,

I try to read a binary file with this code:

Private Sub CommandButton1_Click()
Dim intFileNum%, byteTemp As Byte, intCellRow
Dim arg As String

intFileNum = FreeFile
intCellRow = 0
Open "C:\test" For Binary Access Read As intFileNum
Do While Not EOF(intFileNum)
intCellRow = intCellRow + 1
Get intFileNum, , byteTemp
Cells(intCellRow, 1) = byteTemp
Loop
Close intFileNum
End Sub

But how could I modify the code to read first 8 bytes and after that 4 bytes ?

Regards
Per
 
You can read portions of the file either to fixed length string variable:

[tt]Dim strTemp as String
' ...
strTemp=String(8," ")
Get intFileNum, , strTemp
intCellRow = 1
Cells(intCellRow, 1) = strTemp
Do While Not EOF(intFileNum)
intCellRow = intCellRow + 1
strTemp=String(4," ")
Get intFileNum, , strTemp
Cells(intCellRow, 1) = byteTemp
Loop[/tt]

or to Long (4 bytes) and mix first two results.


combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top