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

    Line Input #1, line...how do i read ahead one line (or back up one line)

    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
    [email protected]



  2. #2
    Join Date
    Dec 1999
    Location
    Israel
    Posts
    101

    Re: Line Input #1, line...how do i read ahead one line (or back up one line)

    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!


  3. #3
    Join Date
    Jun 2000
    Location
    Bavaria, Germany
    Posts
    3

    Re: Line Input #1, line...how do i read ahead one line (or back up one line)

    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).


  4. #4
    Guest

    Re: Line Input #1, line...how do i read ahead one line (or back up one line)

    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




  5. #5
    Join Date
    Dec 1999
    Location
    Israel
    Posts
    101

    Re: Line Input #1, line...how do i read ahead one line (or back up one line)

    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!


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