Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

dumping data from a text file into a list box

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
brianscousin
Asked:
brianscousin
1 Solution
 
WolfgangKoenigCommented:
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
 
Ryan ChongCommented:
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
 
Ryan ChongCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Ryan ChongCommented:
> TempArray(0) = myTeam(i).Name
             
should be:

myTeam(i).Name = TempArray(0)

and follows..
0
 
Ryan ChongCommented:
And just curious:

"football league" = "America football league" or "soccer league"? but basically it's same concept. Cheers
0
 
brianscousinAuthor Commented:
thanks people
0
 
Chandramouli kArchitectCommented:
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
 
DanRollinsCommented:
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
 
kodiakbearCommented:
Moving to the paq

kb
Experts Exchange Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now