早教吧 育儿知识 作业答案 考试题库 百科 知识分享

vb,1-100整数加减法自动出题器,急用!要求:1,按回车出随机数,输入答案就显示对错(诸如你真聪明,别灰心继续努力之类的),并清空答案框随机出下一题.2,计时器计时,每两分钟做出一次总结并

题目详情
vb,1-100整数加减法自动出题器,急用!
要求:
1,按回车出随机数,输入答案就显示对错(诸如你真聪明,别灰心继续努力之类的),并清空答案框随机出下一题.
2,计时器计时,每两分钟做出一次总结并列出总结数据:做的总题数,对错题数.
▼优质解答
答案和解析
添加2个label控件,label1显示算式,label2显示进行时间
添加1个text控件,用于输入结果
添加1个command控件,用于开始
添加1个timer控件,用于计时
程序如下,已经过测试
Option Explicit
Dim starttime As Long,sum As Integer,tOK As Integer,tBad As Integer
Dim result As Integer
Private Sub Command1_Click()
Command1.Enabled = False
Command1.Caption = "运行中"
Text1.Enabled = True
Call Random
sum = 0
tOK = 0
tBad = 0
starttime = Timer()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Label1.Caption = ""
Text1.Text = ""
Text1.Enabled = False
Command1.Caption = "开始计时"
Timer1.Interval = 100
Timer1.Enabled = False
Label2.Caption = ""
End Sub
Private Sub Random()
Dim a,b,c
Randomize
sum = sum + 1
a = Int(Rnd * 100 + 1)
b = Int(Rnd * 2)
c = Int(Rnd * 100 + 1)
If b = 1 Then
result = a + c
Label1.Caption = a & " + " & c & " ="
Else
If a < c Then
Label1.Caption = c & " - " & a & " ="
Else
Label1.Caption = a & " - " & c & " ="
End If
result = Abs(a - c)
End If
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim d As Integer
d = -1
If KeyAscii = 13 Then
If IsNumeric(Trim(Text1.Text)) Then d = Val(Text1.Text)
If d = result Then
MsgBox "你真聪明",vbOKOnly
tOK = tOK + 1
Else
MsgBox "别灰心继续努力"
tBad = tBad + 1
End If
Call Random
End If
End Sub
Private Sub Timer1_Timer()
Label2.Caption = "已过去 " & Format(Timer() - starttime,"0.00") & " 秒"
If Timer() - starttime >= 120 Then
Timer1.Enabled = False
Text1.Enabled = False
Command1.Enabled = True
Command1.Caption = "开始计时"
Label2.Caption = ""
MsgBox "总题数:" & sum & vbCrLf & "对 " & tOK & " 题" & vbCrLf & "错 " & tBad & " 题"
End If
End Sub
看了 vb,1-100整数加减法自...的网友还看了以下: