CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60

    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.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Look
    Attached Files Attached Files
    ...at present time, using mainly Net 4.0, Vs 2010



    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.

  3. #3
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60
    Thanks! It works gr8 now....

    I jus got a bit confused with the record numbers.

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured