Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleRead fixed-length records from a file
Keywordsfixed-length, fixed length, record, random access, file
CategoriesFiles & Directories, Software Engineering
 
Open the file for random access and read each record.

Note that the input variable file_record should have the same length as the file records. This variable can be a single fixed length string as in this example, or a user-defined type created using a Type statement.

 
Private Sub Form_Load()
Const RECORD_LENGTH = 10

Dim fnum As Integer
Dim file_name As String
Dim file_record As String * RECORD_LENGTH
Dim i As Integer

    ' Get the file name.
    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = _
        file_name & "\"
    file_name = file_name & "Fruit.txt"

    ' Open the file.
    fnum = FreeFile
    Open file_name For Random As #fnum Len = RECORD_LENGTH

    ' Read the records.
    For i = 1 To LOF(fnum) \ RECORD_LENGTH
        Get #fnum, i, file_record
        Debug.Print "[" & file_record & "]"
        List1.AddItem Trim$(file_record)
    Next i

    ' Close the file.
    Close #fnum
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated