帮忙写一道VB编程题
题目:熟悉随机函数和Timer控件的使用。单击“开始”按钮以后每隔0.01秒产生2个10~99之间的随机数,如果这两个数之和为100,则停止产生新的数,显示结果。随机数的...
题目:熟悉随机函数和Timer控件的使用。单击“开始”按钮以后每隔0.01秒产生2个10~99之间的随机数,如果这两个数之和为100,则停止产生新的数,显示结果。随机数的界面如图
展开
5个回答
展开全部
Private Sub Command1_Click()
Timer1.Enabled = True
a = 0
End Sub
Private Sub Timer1_Timer()
Randomize
a = a + 1
Text1.Text = Str(a)
Text2.Text = Int(Str(Rnd * 89) + 10)
Text3.Text = Int(Str(Rnd * 89) + 10)
If (Val(Text2.Text) + Val(Text3.Text) = 100) Then
Text4.Text = 100
Timer1.Enabled = False
End If
End Sub
'text1为显示多少次,
'text2为第一个数。
'text3为第二个数。
'text4为和。
'timer控件中Enabled 设为false,interval设为10。
Timer1.Enabled = True
a = 0
End Sub
Private Sub Timer1_Timer()
Randomize
a = a + 1
Text1.Text = Str(a)
Text2.Text = Int(Str(Rnd * 89) + 10)
Text3.Text = Int(Str(Rnd * 89) + 10)
If (Val(Text2.Text) + Val(Text3.Text) = 100) Then
Text4.Text = 100
Timer1.Enabled = False
End If
End Sub
'text1为显示多少次,
'text2为第一个数。
'text3为第二个数。
'text4为和。
'timer控件中Enabled 设为false,interval设为10。
展开全部
Dim a As Integer
Private Sub Timer1_Timer()
Dim b, c, d As Integer
b = Fix(Rnd * (89)) + 10
c = Fix(Rnd * (89)) + 10
Text1.Text = b
Text2.Text = c
a = a + 1
Text3 = a
d = b + c
Text4 = d
If 100 = d Then Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim b, c, d As Integer
b = Fix(Rnd * (89)) + 10
c = Fix(Rnd * (89)) + 10
Text1.Text = b
Text2.Text = c
a = a + 1
Text3 = a
d = b + c
Text4 = d
If 100 = d Then Timer1.Enabled = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 10
End Sub
Private Sub Command1_Click()
Randomize Timer
Command1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim a As Integer, b As Integer
a = Int(Rnd * 90) + 10
b = Int(Rnd * 90) + 10
If a + b = 100 Then
Timer1.Enabled = False
Text1 = a
Text2 = b
Command1.Enabled = True
End If
End Sub
Timer1.Enabled = False
Timer1.Interval = 10
End Sub
Private Sub Command1_Click()
Randomize Timer
Command1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim a As Integer, b As Integer
a = Int(Rnd * 90) + 10
b = Int(Rnd * 90) + 10
If a + b = 100 Then
Timer1.Enabled = False
Text1 = a
Text2 = b
Command1.Enabled = True
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有取整,因为没有要求是随机整数
Private Sub Command1_Click()
Timer1.Interval = 10
Text1.Text = 0
End Sub
Private Sub Timer1_Timer()
Text1.Text = Text1.Text + 1
Text2.Text = Rnd * 89 + 10
Text3.Text = Rnd * 89 + 10
Text4.Text = Text2.Text + Text3.Text
If Val(Text4.Text) = 100 Then Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
Timer1.Interval = 10
Text1.Text = 0
End Sub
Private Sub Timer1_Timer()
Text1.Text = Text1.Text + 1
Text2.Text = Rnd * 89 + 10
Text3.Text = Rnd * 89 + 10
Text4.Text = Text2.Text + Text3.Text
If Val(Text4.Text) = 100 Then Timer1.Enabled = False
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
text1.Text = i
text2.Text = Int(90 * Rnd + 10)
Randomize
text3.Text = Int(90 * Rnd + 10)
Sum = Val(ext2.Text) + Val(text3.Text)
text3.Text = Sum
If Sum = 100 Then Timer1.Interval = 0
End Sub
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static i As Integer
i = i + 1
text1.Text = i
text2.Text = Int(90 * Rnd + 10)
Randomize
text3.Text = Int(90 * Rnd + 10)
Sum = Val(ext2.Text) + Val(text3.Text)
text3.Text = Sum
If Sum = 100 Then Timer1.Interval = 0
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询