|
-
November 11th, 2003, 12:30 PM
#1
File Reading/Writing Probs...
Hi all,
I have to write and read data to a text file for student info, using the RANDOM command. But if I have a number of entries, i cant seem to get the data for the other entries only the 1st one. Here is my code:
Code:
'Declarations
Dim MyStudent As Student '10 students
Dim FileNumber, RecordLength As Integer
'Declare Types
Private Type Student
ID As Integer
FName As String * 20
LName As String * 20
DOB As Date
End Type
'Writing the data:
Private Sub CmdWrite_Click()
'Store text box data into "MyStudent" variables for data output
MyStudent.ID = TxtID
MyStudent.FName = TxtFName
MyStudent.LName = TxtLName
MyStudent.DOB = TxtDOB
'Automatically keep track of the current file number
FileNumber = FreeFile
RecordLength = Len(MyStudent)
Open App.Path & "\Student Data.Txt" For Random As FileNumber Len = RecordLength
Put FileNumber, MyStudent.ID, MyStudent
Close FileNumber
End Sub
'Reading the data:
Private Sub CmdRead_Click()
Dim LocalStudent As Student
Dim FileNumber As Integer
FileNumber = FreeFile
Open App.Path & "\Student Data.Txt" For Random As FileNumber
Get FileNumber, 1, LocalStudent
TxtID = LocalStudent.ID
TxtFName = LocalStudent.FName
TxtLName = LocalStudent.LName
TxtDOB = LocalStudent.DOB
Close FileNumber
End Sub
Where it says Get FileNumber, 1, LocalStudent I cant change the 1 to 2 for the 2nd record, it doesnt bring back any data, jus 0's??
Any info, thanks
Mark
Last edited by Cimperiali; November 11th, 2003 at 12:33 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|