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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileGet on Byte Array

Status
Not open for further replies.

CraigIT

IS-IT--Management
Nov 12, 2003
1
US
I use FileGet("somefile",myStructure) to read data from a file. I would like to do the same thing on a BYTE array. Is it possible to read in a structure from a BYTE array?

Thanks in advance for any advice.
 
Hey man - check out the Binary reader it is much faster

Regards,
Terry

'''''THE CODE

Option Strict On
Option Explicit On

Imports System.IO
Imports System.String
Imports System.Windows.Forms



Public Function Read_Binary_Data(ByRef sXfile As String) As Int32

Dim BRead As BinaryReader
Dim BWrite As BinaryWriter
Dim FStream As FileStream
Dim bArray() As Byte
'''''Dim sXfile As String


sXfile= "C:\MyBinaryfile.bin" 'Your file name goes here

Try
FStream = New FileStream(sXfile, FileMode.Open, FileAccess.Read, FileShare.Read)
'BWrite = New BinaryWriter(FStream)
BRead = New BinaryReader(FStream)

Catch Errz As Exception
Return (-1) 'FAILURE!
Exit Function

End Try

Redim bArray(100) 'Dim the byte array to read 100 bytes - element 0 to 99

'Seek past the first 50 bytes in file before I attempt to read array
BRead.BaseStream.Seek(50, SeekOrigin.Begin)

bArray = bcRead.ReadBytes(bArray.Length) 'The bytes

BRead.Close()
BWrite.Close()
FStream.Close()

Return (0) 'SUCCESS!

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top