A Few I/O Examples

 

//
// List Box to Flat File
//
FN = FreeFile
Open FileName For Output As FN
For i = lstSelections.ListCount - 1 To 0 Step -1
        Print #FN, lstSelections.List(i)
Next i
Close FN



//
// List Box to Printer
//
For i = lstSelections.ListCount - 1 To 0 Step -1
        Printer.Print vbTab & lstSelections.List(i)
Next I



//
// Flat File to List Box
//
FN = FreeFile
Open FileName For Input As FN
Do While Not EOF(FN)
        Line Input #FN, IOArea
        lstSelections.AddItem IOArea
Loop
Close FN



//
// Building the Full FileSpec
//
Private Function strFileSpec(strFileName As String) As String
        Dim strPath As String
        strPath = App.Path

If Right(strPath, 1) <> "\" Then
    strPath = strPath & "\"
End If

strFileSpec = strPath & strFileName

End Function


//
//  Example using LOF
//
Open strFileName For Input As intFN

lngLength = LOF(intFN)
If lngLength < 32767 Then
    strInput = Input(lngLength, intFN)
Else
    strInput = "Sorry, but the file is too large"
End If

Close intFN

 

//
//  How many records in a Random Access File
//
RecordCount = LOF(intFN) / Len(IOArea)

 

//
//  Some Random Access Functions
//

// Always get a File Number
intFN = FreeFile

// Open the File using the Length of the Record
Open strFileSpec For Random As #intFN Len = Len(IOArea)

// ALWAYS Close the File
Close #fnAddress

// Get a specific Record
Get #intFN, intRecNumber, IOArea

// Get the Next Record
Get #intFN, , IOArea

// Write (or Rewrite) a Record
Put #intFN, intRecNumber, IOArea