在窗体上放一个text1文本框用来显示抽取的数,放一个lable1标签用来显示抽到第几个了,放一个command1命令按钮用来执行抽取。在代码窗口粘贴以下代码:
Dim B(100) As Single, I As Single
Private Sub Command1_Click()
Dim A As Single, j As Single, L As Boolean
Randomize
A = Int((100 * Rnd) + 1)'取得1-100间的随机数
L = False
For j = 0 To I
If A = B(j) Then
L = True
Exit For
End If
Next
If L = False Then ’只有没抽取过的数才算,才显示在文本框
I = I + 1
Text1.Text = A
B(j) = A
Label1.Caption = "这是第" & I & "个"
Else
Text1.Text = "此数已抽取过"
End If
If I >= 100 Then Command1.Enabled = False ’全部数都抽出后,命令按钮失效
End Sub
[
本帖最后由 zhengang1026 于 2014-11-7 17:02 编辑 ]