|
-
Dec 11th, 2000, 12:18 PM
#1
Thread Starter
_______
I have a text file with 5 names, 5 numbers
ie
"Jim",444
"Mary",545
"Slim",234
"Rita",1234
"Me", 469
I now play a game as Harry and score 544
I want to sort the file (descending) and lose the least,
[Slim in this case] while adding Harry. I can sort one dimensional arrays but I haven't played with 2 if that were an option and I somehow think it could be.
"Rita", 1234
"Mary", 545
"Harry", 544
"Me", 469
"Jim", 444
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 11th, 2000, 12:37 PM
#2
transcendental analytic
If you want to sort this first time only, and with 5 items initially unsorted, you just could use the bubble sort you used to like For multidimensioned arrays, i'm not sure what you mean, if you have a variant array with strings and numerics, or a string array with numeric strings for the results. It would be better to use a udt intead since you can handle both the strings and numerics. All sort algoritms have a part where it swaps two items, instead of just swaping the numbers, you swap the names at the same time with the same indexes.
If you save the file and have it sorted next time, you could implement a binary search which will stick in the next name at next position. to remove the last item, you just redim preserve the array. For multidimensional arrays you have to use the last dimension as the dynamic one.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 11th, 2000, 06:09 PM
#3
Thread Starter
_______
<?>
kedaman:
Thanks, but being as I'm too lazy to research the subject, I will opt out for the database and just sort the recordset by score.
Thanks again,
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 12th, 2000, 07:07 AM
#4
Thread Starter
_______
<?>
In case anyone is interested as there were a few views.
Code:
If Dir(App.Path & "/db1.mdb") <> "" Then
Dim db As Database
Data1.DatabaseName = App.Path & "/db1.mdb"
Set db = Workspaces(0).OpenDatabase(Data1.DatabaseName)
Dim sql As String
sql = "select * from table1 order by field2 desc"
Set Data1.Recordset = db.OpenRecordset(sql)
'add the latest player and refresh recordset
Data1.Recordset.AddNew
Data1.Recordset!field1 = NameOfPlayer(1).Name
Data1.Recordset!field2 = NameOfPlayer(1).Score
Data1.Recordset.Update
Data1.Refresh
Dim i As Integer
'get rid of surplus
Data1.Recordset.MoveFirst
While Data1.Recordset.RecordCount > 5
Data1.Recordset.MoveLast
Data1.Recordset.Delete
Wend
'start at front end and list the five top players
Data1.Recordset.MoveFirst
frmTop.List1.Clear
frmTop.List1.FontSize = 10
frmTop.List.FontBold = True
frmTop.List1.AddItem "Top Five Scorers"
frmTop.List1.AddItem ""
While Not Data1.Recordset.EOF
frmTop.List1.AddItem Data1.Recordset!field2 & " " & Data1.Recordset!field1
Data1.Recordset.MoveNext
Wend
frmTop.Visible = True
FrmMain.Visible = False
End If
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 12th, 2000, 07:50 AM
#5
Frenzied Member
dont use data control
in my opinion data control is for those that are REALLY lazy 
(and i dont think you are one of THOSE since you help a lot of people out)
use pure ADO Code instead of data control
and from the looks of it
your using DAO
ADO is better in my opinion and many others
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|