仪器社区

vb 计时器怎么控制随机数的产生

songxin520chen 2009-12-12
题目是:程序运行是,单击“开始”按钮,每秒钟产生3个1到6的随机数字 单击“暂停”按钮,终止随机数的产生。 随机数的代码我会,但不知道计时器的代码怎么写 Private Sub Command1_Click() Cls Dim a(3) As Integer For l = 1 To 3 x = Int(Rnd * 10)... 题目是:程序运行是,单击“开始”按钮,每秒钟产生3个1到6的随机数字 单击“暂停”按钮,终止随机数的产生。 随机数的代码我会,但不知道计时器的代码怎么写 Private Sub Command1_Click() Cls Dim a(3) As Integer For l = 1 To 3 x = Int(Rnd * 10) Debug.Print x For i = 1 To 6 If i = x Then Exit For End If Next i Next l Label1.Caption = Int((Rnd * 6) + 1) Label2.Caption = Int((Rnd * 6) + 1) Label3.Caption = Int((Rnd * 6) + 1) End Sub Private Sub Timer1_Timer() End Sub 谁能帮写下代码啊
评论
全部评论
vans来
你随机怎么不加上Randomize?给你改了
需要两个按钮 两个label,一个时钟

Private Sub Command1_Click()
Cls
Dim a(3) As Integer
For l = 1 To 3
Randomize
x = Int(Rnd * 10)
Debug.Print x
For i = 1 To 6
If i = x Then
Exit For
End If
Next i
Next l
Label1.Caption = Int((Rnd * 6) + 1)
Label2.Caption = Int((Rnd * 6) + 1)
Label3.Caption = Int((Rnd * 6) + 1)
End Sub
Private Sub Command2_Click()
If Timer1.Enabled = False Then
Timer1.Enabled = True
Command2.Caption = "暂停"
Else
Command2.Caption = "开始"
Timer1.Enabled = False
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = "1000"
Command2.Caption = "开始"
End Sub

Private Sub Timer1_Timer()
Command1_Click
End Sub
14 0 2009-12-13 0条评论 回复
LUOBOBAICAI123
Private Sub Form_Load()
Timer1.Enabled = False: Timer1.Interval = 1000
Command1.Caption = "开始": Command2.Caption = "暂停"
End Sub

'开始按钮
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

'暂停按钮
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

'将你原来的 Command1_Click 中的代码放到 Timer1_Timer 中
Private Sub Timer1_Timer()
Cls
Dim a(3) As Integer
For l = 1 To 3
x = Int(Rnd * 10)
Debug.Print x
For i = 1 To 6
If i = x Then
Exit For
End If
Next i
Next l
Label1.Caption = Int((Rnd * 6) + 1)
Label2.Caption = Int((Rnd * 6) + 1)
Label3.Caption = Int((Rnd * 6) + 1)
End Sub
12 0 2009-12-13 0条评论 回复
冰旭冰旭冰
Private Sub Timer1_Timer()
Dim a(3) As Integer
For l = 1 To 3
x = Int(Rnd * 10)
Debug.Print x
For i = 1 To 6
If i = x Then
Exit For
End If
Next i
Next l
Label1.Caption = Int((Rnd * 6) + 1)
Label2.Caption = Int((Rnd * 6) + 1)
Label3.Caption = Int((Rnd * 6) + 1)
End Sub
8 0 2009-12-13 0条评论 回复
我想要个黑金
'窗体加入这个
Timer1.interval=333 '1秒为1000,这里333即大概1秒3次。

Private Sub Timer1_Timer()
Command1=true ‘加入这行就可以了。
End Sub
以上注释去掉即可。
18 0 2009-12-13 0条评论 回复
您可能感兴趣的社区主题
加载中...
发布 评论