Move/reset to the beginning of a TextStream

C

Conan Kelly

Hello all,

I'm storing values in a string array. I need to loop through a TextStream
for each element in the array.


Dim ptstSource As TextStream
Dim pstrMEDates() As String
Dim pbytArrayElements As Byte

... 'pstrMEDates() gets ReDim'ed along the way
...

For pbytMEDatesIndex = LBound(pstrMEDates) To UBound(pstrMEDates)
Do While Not ptstSource.AtEndOfStream
...
...
Loop
Next pbytMEDatesIndex

After running through the TextStream for the first element,
ptstSource.AtEndOfStream will be true, correct? It doesn't look like there
are any methods for the TextStream object to move to the beginning of the
stream.

I'm guessing that my only option would be to close the TextStream, then
re-open it. Is that correct?

Thanks for any help anyone can provide,

Conan Kelly
 
J

Joel

See Seek in the help menu. You have to open the file using a file number
insted of a "Scripting.FileSystemObject"


Seek Statement


Sets the position for the next read/write operation within a file opened
using the Open statement.

Syntax

Seek [#]filenumber, position

The Seek statement syntax has these parts:

Part Description
filenumber Required. Any valid file number.
position Required. Number in the range 1 – 2,147,483,647, inclusive, that
indicates where the next read/write operation should occur.



Remarks

Record numbers specified in Get and Put statements override file positioning
performed by Seek.

Performing a file-write operation after a Seek operation beyond the end of a
file extends the file. If you attempt a Seek operation to a negative or zero
position, an error occurs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top