Solved

dumping data from a text file into a list box

Posted on 2002-03-19
9
160 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 52

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 52

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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 52

Expert Comment

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

myTeam(i).Name = TempArray(0)

and follows..
0
 
LVL 52

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 78
Problem to line 23 79
Dinamic report to Crosstab query 9 59
Assign a value in Excel V-Basic 3 36
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 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