Option Explicit
Dim k3(1 To 7) As Long '保存7个随机数
Private Sub Command1_Click()
Dim j As String
Dim i As Long
Dim k As Long
Dim k2 As Long
j = Text1.Text '取输入值
If IsNumeric(j) Then '是否是数字
i = CLng(j)
If i > 6 Then '如果小于7,那么在 0-5 中间无法完成任务
k = 1
Do While k <= 7
k3(k) = Int(Rnd() * i) '如果最小值不能为零的话,需要修改这句和上面判断是否能完成那句
For k2 = 1 To k - 1
If k3(k2) = k3(k) Then '最后产生的数与前面的相同
Exit For
End If
Next k2
If k2 = k Then '如果循环顺利全部结束,则取下一个数
k = k + 1
End If
Loop
Call Picture1_Paint '重新刷新一下结果
Else
MsgBox "请输入一个稍大一些的整数", vbCritical
End If
Else
MsgBox "请输入一个整数", vbCritical
End If
End Sub
Private Sub Command2_Click()
Picture1.Cls '清除保存的结果
Dim k2 As Long
For k2 = 1 To 7 '清掉数据结果
k3(k2) = 0
Next k2
End Sub
Private Sub Command3_Click()
Unload Me '关闭自己
End Sub
Private Sub Form_Load()
Randomize Timer '随机化随机数生成器
End Sub
Private Sub Picture1_Paint()
Dim k2 As Long
Picture1.Cls '因为定义picture1自动重绘功能为关,所以手动刷新
If k3(1) <> k3(2) Then
For k2 = 1 To 7
Picture1.Print k3(k2)
Next k2
End If
End Sub