Click to See Complete Forum and Search --> : Line Input #1, line...how do i read ahead one line (or back up one line)


June 18th, 2000, 07:04 PM
I am loading a file line by line using the LIne Input but at one point i need to look ahead at the next line to decided what to do on the current line...how do i look ahead one line? or how do i use the line Input function and then back up? Any help would be greatly appreciated.

Shane Thomas
p.s. please email replys in addition to the reply of post too
shathoma@nmsu.edu

Ruth Glushkin
June 19th, 2000, 01:25 AM
Using Seek() Function you can get the current position inside of your file,
and using Seek Statement you can set this position for desired value.

Good Luck!

M.Drobilitsch
June 19th, 2000, 01:33 AM
You can't do this in Ascii-Mode. Open your File in Binary mode and read with seek() and detect line feeds with the "vbcrlf"-constant or chr(13)/chr(10).

June 19th, 2000, 11:26 AM
Okay do you have a code example on this? I can find in the help the seek but their examples are not helpful. I am kinda doing this

do while not EOF(1)
Line input #1, inputstring
'need to look ahead one Line input #1 and see whats coming up
if comingupline=0
parse(inputstring)
else
parse2(inputstring)
end if

loop
'this is really loose but hopefully it shows the idea.




Thanks in advance. Shane

Ruth Glushkin
June 20th, 2000, 02:09 AM
Try something like this:

Dim lInputstringlen As Long
Dim lPosition As Long

Open "yourfilename.txt" For Input As #1

Do While Not EOF(1)
Line Input #1, inputstring
lInputstringlen = Len(inputstring)
lPosition = Seek(1) ' gets the current position in the file
Seek #1, lPosition - lInputstringlen ' sets the current position line ahead
Loop

Good Luck!