Extracting lines from a text file :)

MiniMe
03-11-2004, 04:57 PM
Hi,

I wonder if somebody could help me here. I have a text file 'Teams.txt' which contains the following:

Wolves vs Charlton Athletic
2
A
Monday
"12:00"
1
RCB
Week No
#2004-03-08#
Wolves vs Fulham
1
A
Monday
"12:00"
2
EHB
Week No
#2004-03-08#
... more teams here

The sequence is repeated after 9 entries, for each fixture. The fixture has information such as time, day, date pitch no etc associated with it. What I want to be able to do is (because there will always be 9 entries) extract the first entry for as many fixtures in the text file. So in effect, what I will end up with is:

Wolves vs Charlton Athletic
Wolves vs Fulham

I have supplied the code I am using to read the file but I've become a bit stuck and would appreciate any help on this matter.

Open App.Path + "Teams.txt" For Input As #1

Do While Not EOF(1)
Line Input #1, strLine

............

Loop

Close #1

Thanks a bunch guys,

MiniMe

VenDiddy
03-11-2004, 05:12 PM
I think you could do something like this:

Dim X as Integer
Dim strTemp as String
Dim arrTemp() as String
Open App.Path + "Teams.txt" For Input As #1
strTemp = Input(LOF(1), 1)
Close #1
arrTemp = split(strTemp,vbCrLf)
For X=0 to UBound(arrTemp) Step 10
txtTeams.Text = txtTeams.Text & arrTemp(X)
If X>0 Then
txtTeams.Text = txtTeams.Text & vbCrLf
Next X

XVB
03-11-2004, 05:14 PM
well if all you want is to extract certain data every 10 lines you could:


If i = 10 Then
Text1.Text = Text1.Text + strline + vbCrLf
i = 1
End If

i = i + 1

put this inside your loop, define i as integer with starting value of 10.

MiniMe
03-11-2004, 05:32 PM
Hi thanx for ur replies, but for some reason, as it stand, I'm getting 10 records of each fixture in my database. Any ideas why?

MiniMe

Open (Path + "/Teams.txt") For Input As #1

rs.Open SQL, con, adOpenStatic, adLockOptimistic

i = 10

Do While Not EOF(1)

Input #1, strLine

If i = 10 Then
newstring = strLine
i = 1
End If

i = i + 1

rs.AddNew

rs!League = newstring

rs.Update

Loop

rs.MoveLast
rs.MoveFirst

Close #1

Phierce
03-11-2004, 05:58 PM
ok here is the easiets, and IMHO best

Private Sub Command1_Click

Dim hFile as Long
Dim sFilename as String

sFilename = App.Path + "Teams.txt"
hFile = FreeFile
Open sFilename For Input As #hFile
Text1.Text = Input$(LOF(hFile), hFile)
Close #hFile

End Sub

MiniMe
03-11-2004, 06:09 PM
Hiya!

It was every line with a fixture on that I wanted to display, not the whole file.

Thank you any way. I found a way now :)

MiniMe

Phierce
03-11-2004, 06:27 PM
Please share the Fix so the next person might be able to see.


thanks!

MiniMe
03-11-2004, 06:34 PM
It was either of XVBs and VenDiddys contributions above.

MiniMe

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum