CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: File Access

  1. #1
    Join Date
    Apr 2000
    Location
    Missouri
    Posts
    16

    File Access

    How can you read a file that has records of varying record sizes. For example a student file that contains the student name and anywhere from 0 to 15 quiz scores:
    Lester Leeroy,10,20,35,40
    Adam West,10,40,70,80,50,70,80


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: File Access

    No problem. The following simple program will open Autoexec.bat file and read it one line at a time then print that line. Line length is irrevelant.

    option Explicit
    Dim strTemp as string
    private Sub Command1_Click()
    Open "C:\Autoexec.bat" for input as #1
    Do Until EOF(1)
    Line input #1, strTemp
    print strTemp
    Loop
    Close #1
    End Sub




    John G

  3. #3
    Join Date
    Apr 2000
    Location
    Missouri
    Posts
    16

    Re: File Access

    Thank you for your reply. What I am looking for is not so much a way to read the entire record but how to read the quiz scores into an array. Not having used Visual Basic very much I am not sure how to proceed. I would nortmally use a For-Next loop but when You do not know how many quiz scores there are how can you set up an indeterminate loop to read them into the program. What would you consider to be your terminating condition?


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: File Access

    You can use Split function


    Dim strInput As String
    Dim aryInput() As String
    Dim intElement As Integer
    strInput = "information1,information2,information3,information4"
    aryInput = Split(strInput,",")
    For intElement = LBound(aryInput) To UBound(aryInput)
    Msgbox aryInput(intElement)
    Next


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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