Copy Code code as follows:
Function Makegroup (Teams () as String) as String
' function function: Randomly grouping 32 teams in a teams array. (Note: Teams array subscript starting from 0)
' The variable definition of the function.
' It's a good habit to show variable declarations.
Dim Tvar As Integer, returnstr as String, tmove as Integer, temp as Integer
' Initialize the random number generator to achieve real randomness.
Randomize (Timer)
For tvar = 1 to 32 ' a total of 32 teams
If (tvar-1) Mod 4 = 0 Then
' Keep the team name and group name in the RETURNSTR variable.
Returnstr = returnstr & vbCrLf & Chr (ASC ("A") + (Tvar \ 4)) & "group:"
End If
Tmove = Int (Rnd * (33-tvar))
RETURNSTR = returnstr & Teams (Tmove) & "."
For temp = Tmove to 30
' Move the portion of the array forward to avoid a team with the same name in the group.
Teams (temp) = Teams (temp + 1)
Next Temp
Next Tvar
' The return value is the result of grouping.
Makegroup = Returnstr
End Function