Using Line Input to go back a line 
Author Message
 Using Line Input to go back a line

Hi there

I am processing a file with Line Input. What I would like to
do is to be able to back a line, upon a certain condition, ie like
using Move with a negative argument.

I tried LineInput -#1 , Textline but to no sucess

Can this be done or should I try something else?

Many thanks

Chris Asaipillai



Sat, 05 Feb 2005 01:32:06 GMT  
 Using Line Input to go back a line
You can't move back through the text file itself, Christopher, but what you
can do is, before you read in a new line, store the old line in a variable:

strOldLine = strCurrentLine
LineInput #1, strCurrentLine

Now if you need the content of the previous line, you can get it from the
variable strOldLine.

--
Brendan Reynolds (MVP)

Access 2000/2002 sample app at
http://brenreyn.brinkster.net
----------------------------

Quote:
> Hi there

> I am processing a file with Line Input. What I would like to
> do is to be able to back a line, upon a certain condition, ie like
> using Move with a negative argument.

> I tried LineInput -#1 , Textline but to no sucess

> Can this be done or should I try something else?

> Many thanks

> Chris Asaipillai



Sat, 05 Feb 2005 02:23:57 GMT  
 Using Line Input to go back a line

Quote:

>I am processing a file with Line Input. What I would like to
>do is to be able to back a line, upon a certain condition, ie like
>using Move with a negative argument.

>I tried LineInput -#1 , Textline but to no sucess

>Can this be done or should I try something else?

Something could be hacked together to do that.  Seek is
useful for this kind of thing.

Instead of that, I almost always use an extra buffer (string
variable) for the previous record.  After you're just about
done processing a record, copy it to a strPrevRecord string
variable.  Then when you're working on the next record, the
content of the previous record is still available.

--
Marsh
MVP [MS Access]



Sat, 05 Feb 2005 02:52:07 GMT  
 Using Line Input to go back a line
You can do this using the Seek function and the Seek statement.

Before you call Line Input #, call the Seek function and store the return
value in a variable.  The Seek function returns the current read/write
position.

If, after calling Line Input #, you want to "go back" (that is, return to
the position in the file at the start of the line you just read), call the
Seek statement using the return value from the Seek function that you stored
before calling Line Input #.

It might look something like this:

Dim iFileNumber As Integer
Dim strLine As String
Dim lPosition As Long
..
..
..
lPosition = Seek(iFileNumber)
strLine = Line Input #iFileNumber, strLine

' Under some condition...
If ... Then
    ' ...return to the position in the file at the start of the line we just
read.
    Seek #iFileNumber, lPosition
End If
..
..
..


Quote:
> Hi there

> I am processing a file with Line Input. What I would like to
> do is to be able to back a line, upon a certain condition, ie like
> using Move with a negative argument.

> I tried LineInput -#1 , Textline but to no sucess

> Can this be done or should I try something else?

> Many thanks

> Chris Asaipillai



Sat, 05 Feb 2005 03:02:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. line input lines greater than 255 characters?

2. reading input line by line

3. vba line input not recognizing end of line

4. Using Input# with blank lines

5. ??? Using Split instead of Line Input to read huge text files

6. Using in-line input

7. 'Line Input' using API/CreateFile

8. code similar to Qbasic INPUT and LINE INPUT keywords

9. Input# and Line Input#

10. PBM: Line numbers used by Goto method do not reflect displayed line numbers in document

11. Inserting a line of text, setting that line to have a particular style, going to the next line, new style

12. MSComm -- serial/modem goes off line

 

 
Powered by phpBB® Forum Software