VB 利用时钟控件自动产生1到6之间的随机整数,点击“开始”按钮运行 然后自动停止
1个回答
展开全部
你要在什么时候/条件下,自动停止?下面的程序生成10个数后自动停止
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static i As Integer
Print Int(Rnd * 6) + 1;
i = i + 1
If i >= 10 Then Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static i As Integer
Print Int(Rnd * 6) + 1;
i = i + 1
If i >= 10 Then Timer1.Enabled = False
End Sub
追问
就是相当于掷骰子那种
点一下开始
然后几秒钟过后自动就停了。
追答
需要三个控件(Command1、Timer1和Label1),停下来时按钮出现
Private Sub Command1_Click()
Timer1.Interval = 20
Timer1.Enabled = True
Command1.Visible = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Int(Rnd * 6) + 1
Timer1.Interval = Timer1.Interval * 1.2
If Timer1.Interval > 300 Then
Timer1.Enabled = False
Command1.Visible = True
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询