Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Taking two passes at at Text File using Do Until Loops

I Am loping through a text file. I need to take two passes at the file. When
I exit the first loop I then proceed to the next loop where I want to start
searching the file again from the first line. However the sData variable is
still set to the line where the first loop exited the Do. How do I restart
this? I tried using the "Open x For Input As #1" again in the second loop
but I recieved an error message saying the file was already open.

'First Pass
Open x For Input As #1
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
If some condition = True Then
Exit Do
End if
Loop

LineCount = 0

'Second Pass
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Do something
Loop

Thanks

EM
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Taking two passes at at Text File using Do Until Loops

Perhaps if you explain what you are actually doing with the file, then maybe
we can give you a different approach then the one you have locked onto. For
example, what is the "some condition" that ends your first loop... what is
the "do something" in your second loop? Also, what kind of data structure is
used in your text file?

--
Rick (MVP - Excel)


"ExcelMonkey" wrote in message
...
I Am loping through a text file. I need to take two passes at the file.
When
I exit the first loop I then proceed to the next loop where I want to
start
searching the file again from the first line. However the sData variable
is
still set to the line where the first loop exited the Do. How do I
restart
this? I tried using the "Open x For Input As #1" again in the second loop
but I recieved an error message saying the file was already open.

'First Pass
Open x For Input As #1
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
If some condition = True Then
Exit Do
End if
Loop

LineCount = 0

'Second Pass
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Do something
Loop

Thanks

EM


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Taking two passes at at Text File using Do Until Loops

My first pass looks for a range of text using a start line and and end line
based on key words. My second pass tranfers this segment of the text into a
text box.

Thanks
EM

"Rick Rothstein" wrote:

Perhaps if you explain what you are actually doing with the file, then maybe
we can give you a different approach then the one you have locked onto. For
example, what is the "some condition" that ends your first loop... what is
the "do something" in your second loop? Also, what kind of data structure is
used in your text file?

--
Rick (MVP - Excel)


"ExcelMonkey" wrote in message
...
I Am loping through a text file. I need to take two passes at the file.
When
I exit the first loop I then proceed to the next loop where I want to
start
searching the file again from the first line. However the sData variable
is
still set to the line where the first loop exited the Do. How do I
restart
this? I tried using the "Open x For Input As #1" again in the second loop
but I recieved an error message saying the file was already open.

'First Pass
Open x For Input As #1
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
If some condition = True Then
Exit Do
End if
Loop

LineCount = 0

'Second Pass
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Do something
Loop

Thanks

EM



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Taking two passes at at Text File using Do Until Loops

Never mind Rick, I instead incorporated everything into the first loop.

Dim sData As String
Dim RangeFound As Boolean

RangeFound = False

'Open file and find start/end lie of code snippet
Open x For Input As #1
Do Until EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Check if line contains sub/function name
If InStr(sData, "Keyword1") + InStr(sData, "Keyword2") 0 Then
RangeFound = True
End If
If RangeFound = True Then
UserForm1.TextBox1.Text = UserForm1.TextBox1.Text & sData & vbCrLf
End If
'Make sure End stmt is associated with right Sub/Function stmt
If RangeFound = True Then
If InStr(sData, "Keyword3") + InStr(sData, "Keyword3") 0 Then
Exit Do
End If
End If
Loop
Close #1

Thanks

EM

"ExcelMonkey" wrote:

My first pass looks for a range of text using a start line and and end line
based on key words. My second pass tranfers this segment of the text into a
text box.

Thanks
EM

"Rick Rothstein" wrote:

Perhaps if you explain what you are actually doing with the file, then maybe
we can give you a different approach then the one you have locked onto. For
example, what is the "some condition" that ends your first loop... what is
the "do something" in your second loop? Also, what kind of data structure is
used in your text file?

--
Rick (MVP - Excel)


"ExcelMonkey" wrote in message
...
I Am loping through a text file. I need to take two passes at the file.
When
I exit the first loop I then proceed to the next loop where I want to
start
searching the file again from the first line. However the sData variable
is
still set to the line where the first loop exited the Do. How do I
restart
this? I tried using the "Open x For Input As #1" again in the second loop
but I recieved an error message saying the file was already open.

'First Pass
Open x For Input As #1
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
If some condition = True Then
Exit Do
End if
Loop

LineCount = 0

'Second Pass
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Do something
Loop

Thanks

EM



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Taking two passes at at Text File using Do Until Loops

Couldn't you just keep track to see if the input line should be skipped or
processed.

Dim ProcessThisLine as boolean
dim sData as string

ProcessThisLine = false
Open x For Input As #1
Do While EOF(1)

Line Input #1, sData

if instr(1,sdata,"startkeyword",vbtextcompare) 0 then
processthisline = true
else
if instr(1,sdata,"endkeyword",vbtextcompare) 0 then
processthisline = false
else
if processthisline = true then
'add it to your textbox
end if
end if
end if

Loop

This will exclude the top and bottom indicator lines. I'm not sure if that's
what you want.

(Untested, uncompiled. Watch for typos!)

ExcelMonkey wrote:

I Am loping through a text file. I need to take two passes at the file. When
I exit the first loop I then proceed to the next loop where I want to start
searching the file again from the first line. However the sData variable is
still set to the line where the first loop exited the Do. How do I restart
this? I tried using the "Open x For Input As #1" again in the second loop
but I recieved an error message saying the file was already open.

'First Pass
Open x For Input As #1
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
If some condition = True Then
Exit Do
End if
Loop

LineCount = 0

'Second Pass
Do While EOF(1)
Line Input #1, sData
LineCount = LineCount + 1
'Do something
Loop

Thanks

EM


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
taking the file extension out of the file name wrkingurl Excel Discussion (Misc queries) 3 July 14th 09 04:50 PM
display text when mouse passes over a line Farooq Sheri Excel Programming 1 March 15th 09 11:24 AM
Excel File Taking Forever to Open MEAD5432 Excel Discussion (Misc queries) 5 June 11th 08 08:58 PM
Taking formula to text Dkline Excel Worksheet Functions 3 April 29th 08 05:14 PM
taking one cell and adding text to it bt707[_5_] Excel Programming 6 October 13th 03 03:53 AM


All times are GMT +1. The time now is 04:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"