' Ch. 10 Demo 2 ' Mr. Minich ' This program illustrates the use of the InputBox function as well ' as a sequential access file opened in the Append mode.
Option Explicit Private Sub cmdRead_Click() Dim intLineNumber As Integer ' pointer to keep track of line that is being read Dim strNextLine As String ' line of text from input file Dim J As Integer ' loop variable intLineNumber = InputBox("What line do you want to see?") Open "C:\Temp\Name.txt" For Input As #1 ' opening sequential access file for input For J = 1 To (intLineNumber - 1) Input #1, strNextLine ' moving through the lines of the sequential access file Next J ' error would occur if intLineNumber is "past end of file" Input #1, strNextLine ' reading the desired line lblLine = strNextLine Close #1 End Sub Private Sub cmdAppend_Click() Dim strFirstName As String * 20 ' user's first name strFirstName = InputBox("Enter your first name:") ' obtaining first name from user Open "C:\Temp\Name.txt" For Append As #1 ' opening sequential access file for append (output) ' 1 is the "channel no." associated with ' this file Write #1, strFirstName ' writing to the first line of the file ' This will overwrite what happens to be on the first ' line by the way. (Print #1, strFirstName would work too.) Close #1 ' You should always close files. End Sub Private Sub cmdExit_Click() Unload Me ' You should unload all forms before exiting. End End Sub