VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "计算机考试"
   ClientHeight    =   4215
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   12
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   4215
   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     =   2955
      ScaleWidth      =   3795
      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 SExp As String
Dim Result!, NOk%, NError%

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(Text1) = Result Then
      Picture1.Print SExp; Text1; Tab(10); "√ "     '计算正确
      NOk = NOk + 1
    Else
      Picture1.Print SExp; Text1; Tab(10); "×"   '计算错误
      NError = NError + 1
    End If
    Text1 = ""
    Text1.SetFocus
    Form_Load                           '下一个表达式生成
End Sub

Private Sub Form_Load()
' 通过产生随机数生成表达式
  Dim Num1%, Num2%, NOp%, Op$   '两个操作数,操代码、操作符
  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




