MikeDutcher
Technical User
I am learning VB 6.0. I have a file with 1 million, 600 byte records. The 600 bytes must be parsed into roughly 100 text and numeric fields. I am processing it as follows:
Open "D:\FILE.TXT" For Input As #1
Do While Not EOF(1)
cnt& = cnt& + 1
Line Input #1, in1$
ParseRec (in1$)
. . .
Loop
. . .
Sub ParseRec(in1$)
firstfield$ = Mid$(in1$, 1, 9)
. . .
lastfield& = Val(Mid$(in1$, 599, 2))
End Sub
Now I read the following in the help documentation.
"Ever since the first version of Visual Basic, files have been processed using the Open statement and other related statements and functions (listed below). These mechanisms will eventually be phased out in favor of the FSO object model, but they are fully supported in Visual Basic 6.0."
Okay, I try to be open-minded and make an attempt to understand this FSO stuff. But now I don't know how to detect the end of file. I now have
Dim fso As New FileSystemObject, fil1 As File, _
ts As TextStream
Set fil1 = fso.GetFile("D:\FILE.TXT"
Set ts = fil1.OpenAsTextStream(ForReading)
in1$ = ts.ReadLine
Do While Len(in1$) = 600
cnt& = cnt& + 1
in1$ = ts.ReadLine
ParseRec (in1$)
. . .
Loop
And eventually I get an error for attempting to read past the end of the file.
Ideas?
Open "D:\FILE.TXT" For Input As #1
Do While Not EOF(1)
cnt& = cnt& + 1
Line Input #1, in1$
ParseRec (in1$)
. . .
Loop
. . .
Sub ParseRec(in1$)
firstfield$ = Mid$(in1$, 1, 9)
. . .
lastfield& = Val(Mid$(in1$, 599, 2))
End Sub
Now I read the following in the help documentation.
"Ever since the first version of Visual Basic, files have been processed using the Open statement and other related statements and functions (listed below). These mechanisms will eventually be phased out in favor of the FSO object model, but they are fully supported in Visual Basic 6.0."
Okay, I try to be open-minded and make an attempt to understand this FSO stuff. But now I don't know how to detect the end of file. I now have
Dim fso As New FileSystemObject, fil1 As File, _
ts As TextStream
Set fil1 = fso.GetFile("D:\FILE.TXT"
Set ts = fil1.OpenAsTextStream(ForReading)
in1$ = ts.ReadLine
Do While Len(in1$) = 600
cnt& = cnt& + 1
in1$ = ts.ReadLine
ParseRec (in1$)
. . .
Loop
And eventually I get an error for attempting to read past the end of the file.
Ideas?