Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

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
0
NeerDeth
Asked:
NeerDeth
  • 4
  • 2
  • 2
  • +2
1 Solution
 
Data-ManCommented:
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
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now