|
Post by donjohn24 on Oct 28, 2022 19:06:58 GMT
Its me again! Some years ago I wrote a program in Visual Basic for running the scoring for a quiz, and providing a visual display of the round and total scores. Unfortunately I appear to have deleted everything about the program from my PCs so I cannot use it to enable me to complete a new version I'm working on in Just Basic. My stumbling block is jut how to code sorting the total scores so that I can display them in order. I have scores stored in an array rdscor(16.16) which contains the score for each of the 16 rounds for each of the 16 teams - whose names are stored in temname$(16). At any point I can total the scores for each team, and put them in array ttscor(16).
I obviously need to sort ttscor() into descending order, perhaps into an array - say rank(16) - that stores the team number. I can then access the team number from the rank array and use it to display the team name and its score from temname$ and ttscor to provide a display of the current ranking of the teams.
I just can't quite work out how to do it. I've done massively more complicated things in the past, but I'm stuck.
Any help would be appreciated.
|
|
|
Post by plus on Oct 28, 2022 20:06:10 GMT
OK first off have you checked JB Help on Sort keyword? It is newish to v2.0 so you may have missed it. If so, check that out! It does allow sorting on multiple dimensions of array, just what you need.
Still stuck? Show the relevant part of some code you've tried? It's easier for helping.
|
|
|
Post by donjohn24 on Oct 28, 2022 20:56:29 GMT
OK first off have you checked JB Help on Sort keyword? It is newish to v2.0 so you may have missed it. If so, check that out! It does allow sorting on multiple dimensions of array, just what you need. Still stuck? Show the relevant part of some code you've tried? It's easier for helping. I did find the Help details on Sort, which I understand, but just can't think how to actually write some code to do what I want - it's like writer's block. I want an array that contains team numbers - not the actual scores - listed in descending order of the scores, but I'm so out of touch I just can't work out how to select and store the data!
|
|
|
Post by plus on Oct 28, 2022 23:03:53 GMT
So you don't have any data stored at present that you'd like to apply to code?
So final report is like this? score 100 team 3 score 99 team 4 score 98 team 1 score 95 team 3 ' team 3 is good! score 94 team 2 score 94 team 3 'dang again! score 93 team 5 ...
Think how the data should be entered? One team, the number, then all their scores then the next team and all their scores.
or by games, say you are storing in a file until day of reckoning Team number, score Team number, score ...
or what scenario do you have in mind?
Programming is usually built around the data structure and that around how it is recorded, that's why I ask these things.
BTW, I personally like putting data in text files. That way I can take any old editor double check and fix mistakes without having to code a bunch of special editing stuff. Either of the above structures would be fine to store in text and easy to process in Basic.
Can you put together a sample .txt file that we can use to test our code?
|
|
|
Post by plus on Oct 29, 2022 0:51:10 GMT
Well I made up my own data and tested ye ole sort:
dim score(16, 16), st(16*16,1) ' list score, team for team = 1 to 16 ' teams down the left side print team; for r = 1 to 16 ' rounds across the screen score(r, team) = int(rnd(0)* 101) ' integers 0 to 100
'overview of scores columns by team rows locate r * 4 + 6, team: print score(r, team);
stIndex = stIndex + 1 ' list of scores and teams st(stIndex, 0) = score(r, team) st(stIndex, 1) = team next print next
' check our load 'for i = 1 to 16*16 ' print i, st(i, 0), st(i, 1) 'next
' to reverse sort highest to lowest put end at start and start at end sort st(), 16*16, 1, 0 print print "Index:", "Score:", "Team:" for i = 1 to 16*16 print i, st(i, 0), st(i, 1) next
|
|
|
Post by donjohn24 on Oct 29, 2022 1:05:30 GMT
Its just gone 2 a.m., but I finally 'got it'! Thanks for looking at the problem, but I'm OK now. Part of the final query was that I got the the array size and sorting column mixed up, and then took a while to realise that the results showed the team NUMBER that was top, not its position.
|
|