|
-
May 2nd, 2000, 04:27 PM
#1
Thread Starter
Hyperactive Member
Extreme sorting function needed
Aaarrggghhhh I'm stuck
Please help me 
I'm developing a program for Beach/volleyball tournament's.
Depending on the teams ranking score they will be sorted into groups.
Lets say that I want 5 groups, then the highest ranked team will be placed
as team 1 in group 1, the second highest ranked team will be team 1 in group 2.
Team ranked as nr 6 will be placed as team 2 in group 5, ranked 7 as team 2 in group 4
....
Se list below
Code:
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
Now heres the trouble, the highest ranked team will allways play the fewest
amount of game's. So If I have less than 25 teams but more than
20 teams the list will look like this.
Code:
for teamcount 21 to 24
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
22 21
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
23 22 21
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
24 23 22 21
Now if a 25'th team enters my tournament then the list will look like the first one.
Of course I want to be able to specify how many groups I want in my tournament.
right now I use an array containing the teams but in "real life" I will collect them
from a database.
I have not been able to get my for-loop to "reverse" correctly
and keep the count correct.
If anyone think they can help me, I would be very thankful
If this isn't clear enough please let me know and I will try to explain further.
Onerrorgoto
Dont be to optimistic, the light at the end of the tunnel might be a train
-
May 2nd, 2000, 05:29 PM
#2
Fanatic Member
Try this.
You need two textboxes, and a command button.
Text1 is the number of groups.
Text2 is the number of teams.
Code:
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim iTemp As Integer
Dim iCount As Integer
Dim iGroup As Integer, iNumTeams As Integer
Dim iLoopStep As Integer, iLoopStart As Integer, iLoopend As Integer
Dim iNumTeamsInGroup As Integer
Dim myArray() As Integer
'get the number of groups
iGroup = Val(Text1.Text)
'get the number of teams
iNumTeams = Val(Text2.Text)
'work out the number of teamse in a group
iNumTeamsInGroup = iNumTeams \ iGroup
If iNumTeams Mod iGroup <> 0 Then
iNumTeamsInGroup = iNumTeamsInGroup + 1
End If
ReDim myArray(1 To iNumTeamsInGroup, 1 To iGroup) As Integer
iLoopStep = 1
iLoopStart = 1
iLoopend = iGroup
For i = 1 To iNumTeamsInGroup
If i = iNumTeamsInGroup Then
If iNumTeams Mod iGroup <> 0 Then
'if the mod is not 0 then we need to set the loop
'to come backwards as team 1 play the least teams
iLoopStart = iGroup
iLoopend = 1
iLoopStep = -1
End If
End If
For j = iLoopStart To iLoopend Step iLoopStep
iCount = iCount + 1
myArray(i, j) = iCount
If iCount = iNumTeams Then
Exit For
End If
Next j
'reverse the loop
iLoopStep = iLoopStep * -1
iTemp = iLoopStart
iLoopStart = iLoopend
iLoopend = iTemp
Next i
'this just builds up a string to display the teams
'in a message box.
Dim myStr As String
For i = 1 To iNumTeamsInGroup
For j = 1 To iGroup
myStr = myStr & myArray(i, j) & " , "
Next j
myStr = myStr & vbCrLf
Next i
MsgBox myStr
End Sub
Iain, thats with an i by the way!
-
May 2nd, 2000, 06:37 PM
#3
Thread Starter
Hyperactive Member
-
May 2nd, 2000, 06:40 PM
#4
Fanatic Member
You're Welcome.
No worries mate. Glad i could help.
Iain, thats with an i by the way!
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
|