Solved

dumping data from a text file into a list box

Posted on 2002-03-19
9
157 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 50

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 50

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 50

Expert Comment

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

myTeam(i).Name = TempArray(0)

and follows..
0
 
LVL 50

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

777 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