I'm trying to create a generic hi-scores table for one of my game apps and also so that I can add it to the code samples for others to use
It's almost finished now but when I add a new score to the table and then sort the scores I find that the rows in the table are being separated instead of being kept together. Here's the section of code that adds the new score to the table and then attempts to sort it...
Code:
Sub UpdateTable(Score,Level) ScoresTable.Cell("Score",9)=Score ScoresTable.Cell("Level",9)=Level ScoresTable.Cell("Date",9)=Date(Now) ScoresTable.TableSort ("Score DESC, Level DESC") ScoresForm.Show End Sub
Can you spot what I'm doing wrong please
Thanks,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Hmm ... I don't see any error in this code sample.
What happens if you try this:
Code:
Sub UpdateTable(Score,Level) ScoresTable.RemoveRow(9) ScoresTable.AddRow(Score, Level, Date(now)) ScoresTable.TableSort ("Score DESC, Level DESC") ScoresForm.Show End Sub
Or what happens, if you change the variable names so that they are different to the column names?
I've also tried to sort using only the Score column but it still ends up with the data in the rows getting mixed up. This is probably really simply to solve but its got me beat
Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
No, both columns are set as cStrings because when the table is first started I display blanks but if I set the columns as cNumber then 0's are displayed which looks a little unsightly.
I don't understand why the data in the rows would get mixed up using either cString or cNumber, surely the data in each row should stay constant, just the position of the row should change in relation to the data that is being sorted.
Thanks,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
TableSort doesn't sort the table once.
It keeps the table sorted all the time.
Now, when you write:
ScoresTable.Cell("Score",9)=Score
Row 9 will change depending on the score value.
The next update (level update) will update another row.
As specci49 wrote you should add a new row at once and you don't need to use TableSort each time (it doesn't do anything).
When I replied earlier I hadn't seen Specci48's reply, we must have both been replying at the same time. I see now what I need to do, instead of updating the values in the cells I should remove the row and then add a new row with the updated data. I'll give it a go and let you know how I do.
Thanks for the help.
Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Thank you, removing the last row then adding a new row has done the trick. I hadn't properly understood that TableSort kept the table sorted even after new data is entered.
It's almost ready to be published now
Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
it doesn't matter that you missed my post. The same happend to me not long ago. Now I reload every thread I had posted to after sending, just to be sure I hadn't missed something.
And in this special case it was a "plus" to miss it because...
... if you had read my post, you may have changed your code which has solved the problem.
... now Erel has referenced to my post (who the fu.. ist specci49 ??? ) and you changed your code which has solved the problem. But additionally now we all know how TableSort is really working since Erel explained, that a table is sorted all the time.