Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Extracting lines from a text file :)


Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2004, 04:57 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default Extracting lines from a text file :)


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
__________________
Nothing is impossible...
Reply With Quote
  #2  
Old 03-11-2004, 05:12 PM
VenDiddy VenDiddy is offline
Regular
 
Join Date: Jan 2004
Posts: 72
Default mmmmk

I think you could do something like this:
Code:
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
Reply With Quote
  #3  
Old 03-11-2004, 05:14 PM
XVB's Avatar
XVB XVB is offline
Senior Contributor

* Expert *
 
Join Date: Oct 2003
Location: Middle of dust and sun.
Posts: 814
Default

well if all you want is to extract certain data every 10 lines you could:

Code:
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.
__________________
[Impossible is not a fact. It's an opinion. - nba]
Reply With Quote
  #4  
Old 03-11-2004, 05:32 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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
__________________
Nothing is impossible...
Reply With Quote
  #5  
Old 03-11-2004, 05:58 PM
Phierce Phierce is offline
Newcomer
 
Join Date: Nov 2003
Location: Denver, CO
Posts: 16
Default

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
Reply With Quote
  #6  
Old 03-11-2004, 06:09 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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
__________________
Nothing is impossible...
Reply With Quote
  #7  
Old 03-11-2004, 06:27 PM
Phierce Phierce is offline
Newcomer
 
Join Date: Nov 2003
Location: Denver, CO
Posts: 16
Default

Please share the Fix so the next person might be able to see.


thanks!
Reply With Quote
  #8  
Old 03-11-2004, 06:34 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

It was either of XVBs and VenDiddys contributions above.

MiniMe
__________________
Nothing is impossible...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading from a text file extracted from a pdf file Dony File I/O and Registry 4 02-27-2004 02:49 AM
Data Format when writting to a text file drumgod File I/O and Registry 3 01-30-2004 06:33 PM
Extracting spacific Text from a file MTgeekMAN General 12 07-06-2002 06:45 PM
Deleting lines from text file... Ice_Frog General 35 06-27-2002 05:49 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->