CONGRATULATIONS!!!
YOU
HAVE
ONLY
6
LESSONS
LEFT!!!
OBJECTIVES
Many new programs need to read and write data to disk files. This lesson
is geared toward learning how to create these files, how to read data
from these files, and how to write data to files. VB uses three methods
to access files: 1) Random access; 2) Sequential access; and 3) Binary
access.
ACCESSING FILES
1. Assuming that there is a user-defined data type that is defined
as follows:
Type EmployeeInfo
Name As String * 40
Age As Integer
End Type
What does the following code do?
Dim FileNum As Integer
Dim Employee As EmployeeInfo
FileNum = FreeFile
Open "EMPLOYEE.DAT" For Random As FileNum Len =
Len(PersonInfo)
Employee.Name = "JOHN SMITH"
Employee.Age = 32
Put FileNum, 5, Employee
2. Assuming that there is a user-defined data type that is defined as
follows:
Type EmployeeInfo
Name As String * 40
Age As Integer
End Type
What does the following code do?
Dim FileNum As Integer
Dim Employee As EmployeeInfo
FileNum = FreeFile
Open "EMOLOYEE.DAT" For Random As FileNum Len =
Len(Employee)
3. What does the following code do?
FileNum = FreeFile
Open "TRY>TXT" For Output As FileNum
Print #FileNum, txtMyText.Text
Close FileNum
4. What do the following statements do?
FileNum = FreeFile
Open "C:\TRY\TRY.TXT" For Apppend As FileNum
5. What does the following code do?
FileNum = Free File
Open "INFO>TXT" For Append As FileNum
txtMyText.Text = Input$(LOF(FileNum), FileNum)
Close FileNum
6. What does the following code do?
FileNum = FreeFile
Open "INFO>TXT" For Append As FileNum
Print #FileNum, txtMyText.Text
Close FileNum
7. What does the following code do?
FileNum = FreeFile
Open "TRY.DAT" For Binary As FileNum
MyString = "THIS IS A TEST!"
Put #FileNum, 75, MyString
8. What does the following code do?
FileNum = FreeFile
Open "TRY.DAT" For Binary as FileNum
MyString = String$(20, "")
Get #FileNum, 75, MyString
MsgBox "MyString=" +MyString
Close FileNum
TEST YOUR PROGRESS
BACK TO HOMEPAGE