|
|
Title | Read bytes from a specific part of a file |
Keywords | file, binary, file position, bytes |
Categories | Files and Directories |
|
|
Open the file for Binary access. Use the Get statement to get the bytes, specifying the starting position as the record number. Determine the length of the read by initializing a string to the right length.
|
|
Private Sub cmdGetText_Click()
Dim file_name As String
Dim fnum As Integer
Dim start_pos As Long
Dim stop_pos As Long
Dim txt As String
file_name = App.Path
If Right$(file_name, 1) <> "\" Then file_name = _
file_name & "\"
file_name = file_name & "Alphabet.txt"
fnum = FreeFile
Open file_name For Binary As #fnum
' Go to the start byte.
start_pos = CLng(txtStart.Text)
stop_pos = CLng(txtStop.Text)
' Grab some characters.
txt = Space$(stop_pos - start_pos + 1)
Get #fnum, start_pos, txt
lblResult.Caption = txt
Close #fnum
End Sub
|
|
|
|
|
|