Results 1 to 3 of 3

Thread: Reading a certain part of text file

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Toronto, Canada
    Posts
    43

    Post

    This is my first post ever on this site. I want to start by saying this site is EXCELLENT. I've been searching the web for good help sites and resources, and I found it. It's here!

    My question: I want to read in a textfile that contains a header, followed by student number and first name. I want to store this using random access, since we can read each data and store it easily. But what is the "file read" command that I use to EXCLUDE the first line (the header)? I have manuals, but they don't tell me how to do this.

  2. #2
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455

    Post

    Hello cgl88,

    Welcome to this great q&a site.

    Answer on your question:

    Private Sub Form_Load()
    Dim Readed As String
    FileNum = FreeFile
    Open "c:\a.txt" For Input As FileNum
    Line Input #FileNum, Readed
    MsgBox Readed
    End Sub

    With the Line command you can read lines from your file.

    Extra:

    For N = 1 To 64 And Not EOF(FileNum)
    Line Input #FileNum, Arr(N)
    Next

    Nice regards,

    michelle.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Toronto, Canada
    Posts
    43

    Post

    The goal of the assignment is to retrieve student information from a text file, and then use random access to add scores and final marks to these same students. Does that mean I should use your "Open X For Input", but when it comes to saving scores, save that data in ANOTHER text file?

    '********DATA FILE FORMAT: ***********
    'Student Number Last Name, First Name
    '491235054 ABRA KADABRA
    '678213246 BELLE RINGMA
    'Length:9 **DELIMITERS?***
    '*************************************
    The above is the information. The code below was an ATTEMPT to retrieve the above and store it in varibles. Needless to say , it did not work!

    Please advise. And thanks for your code. I'll use that to retrieve the student info.

    Chris


    Private Sub cmdOpen_Click()
    intFileNum = FreeFile
    intPosition = 2 'skip header

    Get #intFileNum, intPosition, newStudent 'copy records into varaibles

    txtStudentNo.Text = newStudent.StudentNo
    txtStudentName.Text = newStudent.StudentName
    'txtMark(0) = newStudent.Mark1
    'txtMark(1) = newStudent.Mark2
    'txtMark(2) = newStudent.Mark3
    'txtFinal.Text = newStudent.MarkFinal
    'txtIndex.Text = newStudent.StudentIndex
    Close #intFileNum

    End Sub

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