📄 f3-3.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "计算机考试"
ClientHeight = 4212
ClientLeft = 60
ClientTop = 348
ClientWidth = 4680
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 4212
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdOk
Caption = "确定"
Height = 495
Left = 2640
TabIndex = 4
Top = 240
Width = 735
End
Begin VB.PictureBox Picture1
BackColor = &H80000009&
Height = 3015
Left = 480
ScaleHeight = 2964
ScaleWidth = 3804
TabIndex = 3
Top = 840
Width = 3855
End
Begin VB.CommandButton cmdMark
Caption = "计分"
Height = 495
Left = 3600
TabIndex = 2
Top = 240
Width = 735
End
Begin VB.TextBox txtInput
Height = 495
Left = 1560
TabIndex = 1
Top = 240
Width = 855
End
Begin VB.Label lblExp
Height = 375
Left = 600
TabIndex = 0
Top = 360
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Num1 As Integer, Num2 As Integer '两个操作数
Dim SExp As String
Dim Result As Single '计算结果
Dim NOk As Integer, NError As Integer '统计计算正确与错误数
Private Sub CmdMark_Click()
Picture1.Print "----------------------------------"
Picture1.Print "一共计算 " & (NOk + NError) & " 道题";
Picture1.Print "得分 " & Int(NOk / (NOk + NError) * 100)
End Sub
Private Sub cmdOk_Click()
' 在文本框输入计算结果,按“确定”按钮,在图形框显示正确与否
If Val(txtInput) = Result Then
Picture1.Print SExp; txtInput; Tab(10); "√ " '计算正确
NOk = NOk + 1
Else
Picture1.Print SExp; txtInput; Tab(10); "×" '计算错误
NError = NError + 1
End If
txtInput = "" '下一个表达式生成
txtInput.SetFocus
Form_Load
End Sub
Private Sub Form_Load()
' 通过产生随机数生成表达式
Dim NOp As Integer, Op As String * 1 '操作符
Randomize '初始化随机数生成器
Num1 = Int(10 * Rnd + 1) '产生1-10之间的操作数
Num2 = Int(10 * Rnd + 1) '产生1-10之间的操作数
NOp = Int(4 * Rnd + 1) '产生1-4之间的操作代码
Select Case NOp
Case 1
Op = "+"
Result = Num1 + Num2
Case 2
Op = "-"
Result = Num1 - Num2
Case 3
Op = "×"
Result = Num1 * Num2
Case 4
Op = "÷"
Result = Num1 / Num2
End Select
SExp = Num1 & Op & Num2 & "="
lblExp = SExp
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -