?
Solved

TextStream: move back to top of file?

Posted on 2002-05-29
10
Medium Priority
?
263 Views
Last Modified: 2008-02-01
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
Comment
Question by:SuperMario
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Accepted Solution

by:
raizon earned 150 total points
ID: 7042332
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
 
LVL 3

Author Comment

by:SuperMario
ID: 7042335
Me either... I have restructured my code a little bit.. but thanks anyway :)
0
 
LVL 5

Expert Comment

by:raizon
ID: 7042354
Did you use the textstreamobject or go a different route?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7042584
what do you mean by "top of a text file when reading"?
0
 
LVL 3

Author Comment

by:SuperMario
ID: 7042801
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
 
LVL 2

Expert Comment

by:Crin
ID: 7042824
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7042827
Then, problem was solved by yourself using different approach?
0
 
LVL 2

Expert Comment

by:Crin
ID: 7042839
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
 
LVL 2

Expert Comment

by:Crin
ID: 7042844
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
 
LVL 5

Expert Comment

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question