Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRead bytes from a specific part of a file
Keywordsfile, binary, file position, bytes
CategoriesFiles 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated