ReadLine - 1

MS Access:

I'm importing a text file and bring in each line one-by-one.  The problem is that I need to check ahead of the line I'm processing so I can be sure what to do with the current line.  I want to do a readline command, check that line, and then come back to the original line. The program would be worlds more complicated if I read more than one line in at a time.

Is there a command like ts.readline but move Up the file (one line) instead of Down the file (one line)?

Thanks,
Neer
NeerDethAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Data-ManCOOCommented:
There is a readline command

From the help file:
Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.

Syntax

object.ReadLine

The object argument is always the name of a TextStream object.
0
heer2351Commented:
You simply have to store the current line in a variable and read the next one. Then you can process the lines as required.

Here is some example code:

Public Sub processFile()
  Dim fHandle As Long
  Dim currentLine As String
  Dim nextLine As String
 
  fHandle = FreeFile
 
  Open "c:\test.txt" For Input As fHandle
 
  Input #fHandle, currentLine
 
  Do
    Input #fHandle, nextLine
   
    'Actions on current line based on next line
   
    currentLine = nextLine
  Loop Until EOF(fHandle)
 
  'Actions that might be required on the last line
 
  Close fHandle
End Sub
0
pique_techCommented:
To extend that idea, the question was, can I read the file backwards (up instead of down).

The only way I can imagine is to use the FileSystemObject library objects (FileSystem, TextStream) to load the file into an array of strings one line at a time, then use the array index to move around.  It's pretty inelegant, but it would enable bi-directional movement around the file.  Of course this approach brings its own set of challenges.  I've just tested the concept and so I'm confident it should work, but I haven't tested to "implementation quality".

Hope this helps.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pique_techCommented:
Wow.  I always forget that there was a time before object libraries when this sort of file manipulation was commonplace.

Hat-tip, heer2351.
0
Arthur_WoodCommented:
what you are describing is a technique called 'double buffering'...Read the first two lines into an array.  then check First line against the second line.  When you are finished with the first line, move the second line into the position of fist line, and read line 3 into the position of the seond line.  Repeat to the end of the file.

AW
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NeerDethAuthor Commented:
Now that is interesting, I'll have to think about it though.
0
heer2351Commented:
NeerDeth do you mind explaining why you only give points to Arthur Wood. He describes the technique which I already posted with example code.
0
NeerDethAuthor Commented:
You're right, I screwed up. Very sorry
0
Arthur_WoodCommented:
I have no problem with the Page Admin changing the award.  After all, points are worth the paper they are printed on.

Contact Community Support, explain the error and ask for the error to be corrected.

AW
0
NeerDethAuthor Commented:
alright, I'll give that a shot
0
NeerDethAuthor Commented:
alright, I emailed them and got nothing bad....still waiting.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.