ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Move/reset to the beginning of a TextStream (https://www.excelbanter.com/excel-programming/415999-move-reset-beginning-textstream.html)

Conan Kelly

Move/reset to the beginning of a TextStream
 
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



---------------------------
"Smokin' weed kills your brain cells. Drinkin' only screws up your
liver...ya got 2 a those."
- Earl Hickey (NBC's "My Name is Earl")



joel

Move/reset to the beginning of a TextStream
 
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.


"Conan Kelly" wrote:

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



---------------------------
"Smokin' weed kills your brain cells. Drinkin' only screws up your
liver...ya got 2 a those."
- Earl Hickey (NBC's "My Name is Earl")





All times are GMT +1. The time now is 10:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com