VB生成6个不同随机的数

来源:百度知道 编辑:UC知道 时间:2024/09/18 18:39:53
一个命令按钮
单击同时生成6个大于1小于33不同的整数.
并且才label1.caption xxx2.caption xxx3.xxx xxx4.xxx至6中显示.
分不是问题.

你要的代码来了,已经验证OK!!!

Private Sub Command1_Click()
Dim num(1 To 6) As Integer
Dim i, j, t As Integer
'================得到6个大于1小于33不同的整数
For i = 1 To 6
restart: t = Int((33 - 1 + 1) * Rnd + 1)
For j = 1 To UBound(num)
If num(j) = t Then
GoTo restart
End If
Next j
num(i) = t
Next i
'================显示在标签上
Label1.Caption = num(1)
Label2.Caption = num(2)
Label3.Caption = num(3)
Label4.Caption = num(4)
Label5.Caption = num(5)
Label6.Caption = num(6)
End Sub

以后共同学习,共同研究!!!

Private Sub Command1_Click()
Dim x(1 To 6) As Integer
Randomize
For i = 1 To 6
xxxx:
x(i) = 2 + 31 * Rnd()
For j = 1 To i - 1
If x(j) = x(i) Then
GoTo xxxx
End If
Next
Next
Label1.Caption = x(1)
Label2.Caption = x(2)
Label3.Caption = x(3)
Label4.Caption = x(4)
Label5.Caption = x(5)
Label6.Caption = x(6)