' Ch. 10 Demo 1
' Mr. Minich
' This program illustrates the use of the InputBox function as well
' as a sequential access file and a fixed-length string variable.
Option Explicit
Private Sub cmdEnd_Click()
Unload Me ' You should unload all forms before exiting.
End
End Sub
Private Sub cmdRead_Click()
Dim strLine As String ' line of text from input file
Open "C:\Temp\Name.txt" For Input As #1 ' opening sequential access file for input
Input #1, strLine ' obtaining first line of text from file #1 & storing
' it in the variable strLine
lblLine = strLine
Close #1
End Sub
Private Sub Form_Load()
Dim strFirstName As String * 20 ' user's first name
' The size of string variable is
' limited to 20 characters. It is called a
' fixed-length string variable.
strFirstName = InputBox("Enter your first name:") ' obtaining first name from user
Open "C:\Temp\Name.txt" For Output As #1 ' opening sequential access file for output
' If no file named "Name.txt" exists in the
' Temp directory, then VB will create it.
' 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 also)
Close #1 ' You should always close files.
End Sub