Visual Basic问题,麻烦高手尽快详细解答
来源:百度知道 编辑:UC知道 时间:2024/05/22 11:23:45
【提示】本题算法的关键是产生一位数的加法题,Visual Basic 提供了一个可以产生[0,1)之间均匀分布的随机数的随机函数Rnd。一般地,要产生[a,b]之间的随机整数,可使用表达式:Int((b-a+1)*Rnd)+a
请详细写出你的答案
Dim sum '用于匹配的计算结果
Dim a '第一个数
Dim b '第二个数
Private Sub Command1_Click()
If Command1.Caption = "出题" Then
Command1.Caption = "确定"
Randomize
a = Int((9 * Rnd)) '生成第一个数
b = Int((9 * Rnd)) '生成第二个数
Label_1.Caption = a
Label_2.Caption = b
sum = a + b
Text1.Text = ""
Text1.SetFocus
ElseIf Command1.Caption = "确定" Then
If Text1.Text = sum Then '结果正确的情况
Label2.Caption = "√"
Label2.BackColor = &HFF00&
a = Int((9 * Rnd) + 1)
b = Int((9 * Rnd) + 1)
Label_1.Caption = a
Label_2.Caption = b
sum = a + b
Text1.Text = ""
Text1.SetFocus
Else: Lab