Solved

dumping data from a text file into a list box

Posted on 2002-03-19
9
155 Views
Last Modified: 2010-05-02
i am trying to create a football league table

bascially i want to dump all the data from a text file into a list box (but it has to look like  database, all the same fields under each other) , but as i have saved it as a random file the data in the text fils is in one line and this gives me headaches

also once this data has been placed in i want to able to order the data in ascending order according to the amount of points

im real bad at vb so can anyone help

andrew
0
Comment
Question by:brianscousin
9 Comments
 
LVL 4

Accepted Solution

by:
WolfgangKoenig earned 50 total points
ID: 6879511
When you fill your text data in a Listbox you must insert each row of your table with:
Me.List1.AddItem ("Item11" + vbTab + "Item12" + vbTab + "Item13")
Me.List1.AddItem ("Item21" + vbTab + "Item22" + vbTab + "Item23")
Me.List1.AddItem ("Item31" + vbTab + "Item32" + vbTab + "Item33")
...

What you can see in the example that each column is separated by a vbTab.

"Item23" stands for data item row 2 and column 3


Hope this will help you
Do you need a routine to convert you text in this format ??
WoK;)
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6879513
How is your file saved?

Basically you need to put them (Team's Name?) into an Array. Sort them according to the Total Points:

You can try this:

Define the User Defined Type for the Teams:

Private Type Team
    Name As String
    Played As Integer
    Win As Integer
    Draw As Integer
    Lost As Integer
    GoalFor As Integer
    GoalAgainst As Integer
    Points As Integer
End Type

Then read the file into Array

Dim myTeam() As Team, TempArray() As String
i = 0
Open "C:\abc.txt" For Input As #1
    Do While Not EOF(1)
        Redim Preserve myTeam(i)
        Erase TempArray
        Line Input #1, myFile
        TempArray = Split(myFile,",")
        'The contain must correct
        TempArray(0) = myTeam(i).Name
        TempArray(1) = myTeam(i).Played
        TempArray(2) = myTeam(i).Win
        TempArray(3) = myTeam(i).Draw
        TempArray(4) = myTeam(i).Lost
        TempArray(5) = myTeam(i).GoalFor
        TempArray(6) = myTeam(i).GoalAgainst
        TempArray(7) = myTeam(i).Points
       
        i = i + 1
    Loop
Close #1

Then do a Sort Algorithm refers to Team's Points..
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6879516
Yes, Wolf give an idea, use Control to Sort rather than using Sort Algorithm. Alternatively we can use ListView control to display and sort the Team Standing.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6879518
> TempArray(0) = myTeam(i).Name
             
should be:

myTeam(i).Name = TempArray(0)

and follows..
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6879532
And just curious:

"football league" = "America football league" or "soccer league"? but basically it's same concept. Cheers
0
 

Author Comment

by:brianscousin
ID: 6882143
thanks people
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6883960
Here is the code. Pls try this

You have mentioned that the data in the text file is single line.

Well, to use this code, have a textfile with tab as field delimiter and \n as Record delimiter.

Place a listbox (list1) and a command button(command1) in the form. also add microsoft scripting runtime from project->references menu. (for filesystemobject)

#####################################################

Dim fso As FileSystemObject
Dim f

Private Sub Command1_Click()
 Dim RecordArray
 Set f = fso.OpenTextFile("textfile.txt", ForReading)
 list1.Clear
 RecordArray = Split(f.ReadLine, "\n")
 For i = LBound(RecordArray) To UBound(RecordArray)
    List1.AddItem RecordArray(i)
 Next i
End Sub

Private Sub Form_Load()
 Set fso = New FileSystemObject
End Sub

#################################################

This way u can load the data from a single line textfile into a listbox (or similar controls).

******************************************
if this works, sorting is not an issue.
******************************************

ALL THE BEST
kcm76
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7634162
Hi brianscousin,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept WolfgangKoenig's comment(s) as an answer.

brianscousin, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 7665994
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now