怎么写这个程序`
今天看了一个作业,写一个这样的程序,但是这边怎么写呢~
设计一个由计算机来当小学低年级学生算术老师的VB应用程序,要求给出一系列的两个1~10数的四则运算的算术题,学生输入该题的答案,计算机根据学生的答案判断正确与否,并给出成绩,单击结束命令按钮,退出应用程序。
这些四则运算在一个lable里面 ,
[解决办法]
Option Explicit
Private Sub Command1_Click()
Dim sum As Integer
sum = Val(Label1.Caption) & Label2.Caption & Val(Label3.Caption)
If sum = Val(Trim(Text1.Text)) Then
MsgBox ( "你的结果正确! ")
Else
MsgBox ( "你的结果错误! ")
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "1 "
Label3.Caption = "2 "
Text1.Text = " "
Command1.Caption = "结束 "
End Sub
=============================================
给你参考!!
[解决办法]
Option Explicit
Private Sub Command1_Click()
Dim sum As Integer
sum = Val(Label1.Caption) & Label2.Caption & Val(Label3.Caption)
If sum = Val(Trim(Text1.Text)) Then
MsgBox ( "你的结果正确! ")
Else
MsgBox ( "你的结果错误! ")
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "1 "
Label3.Caption = "2 "
Text1.Text = " "
Command1.Caption = "结束 "
End Sub
=============================================
给你参考!!
[解决办法]
Option Explicit
Private Sub Command1_Click()
Dim sum As Integer
sum = Val(Label1.Caption) & Label2.Caption & Val(Label3.Caption)
If sum = Val(Trim(Text1.Text)) Then
MsgBox ( "你的结果正确! ")
Else
MsgBox ( "你的结果错误! ")
End If
End Sub
Private Sub Form_Load()
Label1.Caption = "1 "
Label3.Caption = "2 "
Text1.Text = " "
Command1.Caption = "结束 "
End Sub
=============================================
给你参考!!
[解决办法]
窗体内控件名称: label1 label2 text1 command1 command2
把以上控件放入窗体后复制如下代码到 代码窗口 运行即可看到效果:
Dim 结果 As Variant
Dim 对 As Integer
Dim 总数 As Integer
Dim 错 As Integer
Private Sub Command1_Click()
If Text1 = 结果 Then
对 = 对 + 1
总数 = 总数 + 1
Label2 = "正确 "
Else
错 = 错 + 1
总数 = 总数 + 1
Label2 = "错误,正确答案是 " & 结果 & " 您给的答案却是 " & Text1.Text
End If
Call 计算
Text1 = " "
End Sub
Private Sub Command2_Click()
分数 = (对 / 总数) * 100
a = "题目总数 " & 总数 & "个 "
a = a & vbCrLf & "答对题目 " & 对 & "个 "
a = a & vbCrLf & "答错题目 " & 错 & "个 "
a = a & vbCrLf & "给分 " & 分数 & "分 "
a = a & vbCrLf & "下面将清空记录重新开始记录 "
总数 = 0
对 = 0
错 = 0
MsgBox a
End Sub
Private Sub Form_Load()
Call 计算
Text1 = " "
Command1.Caption = "下一题 "
Command2.Caption = "结束打分 "
Label2.AutoSize = True
End Sub
Private Sub 计算()
Randomize
a = Int(Rnd * 10) + 1
b = Int(Rnd * 4) + 1
c = Int(Rnd * 10) + 1
If b = 1 Then Label1 = Str(a) & " + " & Str(c) & " = ": 结果 = a + c
If b = 2 Then Label1 = Str(a) & " - " & Str(c) & " = ": 结果 = a - c
If b = 3 Then Label1 = Str(a) & " * " & Str(c) & " = ": 结果 = a * c
If b = 4 Then Label1 = Str(a) & " / " & Str(c) & " = ": 结果 = a / c: If 结果 < 1 Then 结果 = "0 " & Trim(Str(Left(Trim(Str(结果)), 3))) Else 结果 = Trim(Str(Left(Trim(Str(结果)), 4))):: Label2 = "结果只取小数点2位 "
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Call Command1_Click
End Sub
=================================
cike技术交流群 16874787 支持群论坛地址为:http://www.hexi5.com/bbs/index.asp
欢迎加入我们一起学习!