Click to See Complete Forum and Search --> : File Access


St. Nick
October 10th, 2001, 01:51 PM
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

John G Duffy
October 10th, 2001, 04:19 PM
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

St. Nick
October 15th, 2001, 02:45 PM
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?

Iouri
October 15th, 2001, 02:54 PM
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
iouri@hotsheet.com