'作者:星空无月(xkwy)
Private Sub Command1_Click()
Dim i As Integer, k As Integer
Dim strText As String
Dim a(9) As Integer
For i = 0 To 9
Do While Repeat(a(), k, i) '如果重复的话继续获取
k = Int(Rnd * 50 + 1) '获取1~50的整数
Loop
a(i) = k
Next
For i = 0 To 9
strText = strText & " " & a(i)
Next
Label1.AutoSize = True
Label1.Caption = strText
End Sub
Private Function Repeat(a() As Integer, Num As Integer, Index As Integer) As Boolean
'参数:a()表示要判断的数组,Num表示被重复的数字,index表示判断到几号就不看了
Dim j As Integer
For j = LBound(a) To Index '如果有重复则返回True
If Num = a(j) Then Repeat = True: Exit Function
Next
Repeat = False
End Function