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.
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.