• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

TextStream: move back to top of file?

Is there a method I can use to move to the top of a text file when reading? Or do I need to use a different object?

Thanks!
0
SuperMario
Asked:
SuperMario
  • 3
  • 3
  • 2
  • +1
1 Solution
 
raizonCommented:
Only way I know of using the TextStream Object would be to close the file and destroy the object then re open it.  This will put you back at the beginning of the file.  However it doesn't seem to efficient to me.

0
 
SuperMarioAuthor Commented:
Me either... I have restructured my code a little bit.. but thanks anyway :)
0
 
raizonCommented:
Did you use the textstreamobject or go a different route?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richie_SimonettiIT OperationsCommented:
what do you mean by "top of a text file when reading"?
0
 
SuperMarioAuthor Commented:
I went a different route, actually... I was reading in line by line initially and needed to return to the initial state for another function. I ended up writing it in the same piece of code.
0
 
CrinCommented:
You can use following:

FileNum = FreeFile(0)
Open "File.txt" For Random As FileNum Len = 1

And then take text from any position using:

Get FileNum, CurFilePos + i, curchar

However, this require to rewrite LineInput function which is very simple, say if you need help here.

Sincerely,
Crin


0
 
Richie_SimonettiIT OperationsCommented:
Then, problem was solved by yourself using different approach?
0
 
CrinCommented:
Sorry, posted comment without enough explanations.

Get FileNum, CurFilePos, curchar

This line will read ONE symbol into curchar variable taken from CurFilePos position.

public Function CustomLineInput(CurFilePos as long) as string
Dim Result as string, curchar as String * 1, i as long

Result = ""
curchar = ""
i = 0

Do
  Get FileNum, CurFilePos + i, curchar
  if curchar <> chr(13) and curchar <> chr(10) then
    Result = Result & curchar
  end if
Loop Until curchar = chr(13) and CurFilePos + i < LOF(FileNum)

CustomLineInput = Result

End Function

Now you just need to maintain CurFilePos right way.

Sincerely,
Crin
0
 
CrinCommented:
It is night here, so some typos coming...

Loop Until curchar = chr(13) and CurFilePos + i < LOF(FileNum)

should be:

Loop Until curchar = chr(13) or CurFilePos + i = LOF(FileNum)

Sincerely,
Crin

0
 
raizonCommented:
yes I believe that SuperMario did solve this on thier own by using a different approach.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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