Function makegroup(teams() As String) As String '函数功能:对teams数组中的32支球队进行随机分组.(注:teams数组下标从0开始) '函数的变量定义. '显示变量声明是一个好习惯. Dim tvar As Integer, returnstr As String, tmove As Integer, temp As Integer '初始化随机数产生器实现真正的随机性. Randomize (Timer) For tvar = 1 To 32 '共有32支球队 If (tvar - 1) Mod 4 = 0 Then '将分组球队名称及组名存入returnstr变量中. returnstr = returnstr vbCrLf Chr(Asc("A") + (tvar \&;4)) "组:" End If tmove = Int(Rnd * (33 - tvar)) returnstr = returnstr teams(tmove) "." For temp = tmove To 30 '将数组的部分前移避免组中存在同名球队. teams(temp) = teams(temp + 1) Next temp Next tvar '返回值为分组后的结果. makegroup = returnstr End Function