Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching a text file

Status
Not open for further replies.

JacobY

Programmer
Jul 27, 2002
6
0
0
US
I am trying to gather the line after a certain value in a text file.... Any help would be appreciated.

Sub GetLayerNames()
Dim DPFLine As Variant
Dim I As Integer
Open "C:\Documents and Settings\JEY\Desktop\DEMO.las" For Input As #1
While Not EOF(1)
Line Input #1, DPFLine
If DPFLine = " 8" Then
'Here is where I want the line after

End If
Wend
Close #1
 
If you want the next line do something like this:

Sub GetLayerNames()
Dim DPFLine As Variant
Dim I As Integer
Dim varLine As Variant '<== New
Dim blnFound As Boolean '<== New
Open &quot;C:\Documents and Settings\JEY\Desktop\DEMO.las&quot; For Input As #1
While Not EOF(1)
Line Input #1, DPFLine
If DPFLine = &quot; 8&quot; Then
blnFound = True
ElseIf blnFound Then
varLine = DPFLine
blnFound = False
Else
'Maybe other processing
End If
Wend
Close #1

Good Luck!
 
Thanks for the help! (but)

Problem is that I have volumes of different information within the text file and I specifically need the line after.

Here is an example of the text file...

0
LAYERSTATEDICTIONARY
0
LAYERSTATE
1
DEMO
91
-1
8
EP-STMSYM
90
8
62
4
370
-3
6
CONTINUOUS
2
Color_4
8
up-stmout
90
8
62
51
370
-3
6
CONTINUOUS
2
Color_51
8
EP-SWLSYM
90
8
62
11
370
-3
6
CONTINUOUS
2
Color_11
8
_KTI_CONTROL
90
11
62
7
370
-3
6
CONTINUOUS
2
Color_7
8
fp-carsym
90
 
To further clarify my direction...
I have been thinking along these lines...
But it just isn't clicking...

While Not EOF(1)
Line Input #1, DPFLine
If DPFLine = &quot; 8&quot; Then
Line Input #1, DPFLine(I + 1)
 
My regrets,

I was too hasty to reply and didn't read all of the code (or even try it out!). SBendBuckeye was correct.

Regards to you. Jacob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top