数组中取十个互不相同的数

时间:2023-01-24 08:04:34

 

Private Sub Command1_Click()
Dim a(10) As Integer
Dim mystr As String
Dim printstr As String
   a(1) = Int(Rnd() * 100 + 1)
   printstr = Str(a(1))
   For i = 2 To 10
   t = Int(Rnd() * 100 + 1)
   mystr = "
"
        For k = 1 To i - 1
          If t = a(k) Then
           mystr = "
不要
"
          Exit For
          End If
        Next
        If mystr = "
不要
" Then
            i = i - 1
        Else
            a(i) = t
 printstr = printstr + Str(t)

        End If
 
   Next
   Print printstr
End Sub