⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calc.frm

📁 简单计算器
💻 FRM
字号:
VERSION 5.00
Begin VB.Form main 
   BackColor       =   &H00404000&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "计算器"
   ClientHeight    =   2970
   ClientLeft      =   2580
   ClientTop       =   1485
   ClientWidth     =   3270
   ClipControls    =   0   'False
   BeginProperty Font 
      Name            =   "System"
      Size            =   9.75
      Charset         =   0
      Weight          =   700
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "CALC.frx":0000
   LinkMode        =   1  'Source
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   2970
   ScaleWidth      =   3270
   StartUpPosition =   2  '屏幕中心
   WhatsThisHelp   =   -1  'True
   Begin VB.CommandButton negcmd 
      Caption         =   "+/-"
      Height          =   480
      Left            =   720
      TabIndex        =   20
      Top             =   2400
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "7"
      Height          =   480
      Index           =   7
      Left            =   120
      TabIndex        =   7
      Top             =   600
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "8"
      Height          =   480
      Index           =   8
      Left            =   720
      TabIndex        =   8
      Top             =   600
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "9"
      Height          =   480
      Index           =   9
      Left            =   1320
      TabIndex        =   9
      Top             =   600
      Width           =   480
   End
   Begin VB.CommandButton Cancel 
      Caption         =   "C"
      Height          =   480
      Left            =   2040
      TabIndex        =   10
      Top             =   600
      Width           =   480
   End
   Begin VB.CommandButton CancelEntry 
      Caption         =   "CE"
      Height          =   480
      Left            =   2640
      TabIndex        =   11
      Top             =   600
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "4"
      Height          =   480
      Index           =   4
      Left            =   120
      TabIndex        =   4
      Top             =   1200
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "5"
      Height          =   480
      Index           =   5
      Left            =   720
      TabIndex        =   5
      Top             =   1200
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "6"
      Height          =   480
      Index           =   6
      Left            =   1320
      TabIndex        =   6
      Top             =   1200
      Width           =   480
   End
   Begin VB.CommandButton Operator 
      Caption         =   "+"
      Height          =   480
      Index           =   1
      Left            =   2040
      TabIndex        =   12
      Top             =   1200
      Width           =   480
   End
   Begin VB.CommandButton Operator 
      Caption         =   "-"
      Height          =   480
      Index           =   3
      Left            =   2640
      TabIndex        =   13
      Top             =   1200
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "1"
      Height          =   480
      Index           =   1
      Left            =   120
      TabIndex        =   1
      Top             =   1800
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "2"
      Height          =   480
      Index           =   2
      Left            =   720
      TabIndex        =   2
      Top             =   1800
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "3"
      Height          =   480
      Index           =   3
      Left            =   1320
      TabIndex        =   3
      Top             =   1800
      Width           =   480
   End
   Begin VB.CommandButton Operator 
      Caption         =   "X"
      Height          =   480
      Index           =   2
      Left            =   2040
      TabIndex        =   14
      Top             =   1800
      Width           =   480
   End
   Begin VB.CommandButton Operator 
      Caption         =   "/"
      Height          =   480
      Index           =   0
      Left            =   2640
      TabIndex        =   15
      Top             =   1800
      Width           =   480
   End
   Begin VB.CommandButton Number 
      Caption         =   "0"
      Height          =   480
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   2400
      Width           =   480
   End
   Begin VB.CommandButton Decimal 
      Caption         =   "."
      Height          =   480
      Left            =   1320
      TabIndex        =   18
      Top             =   2400
      Width           =   480
   End
   Begin VB.CommandButton Operator 
      Caption         =   "="
      Height          =   480
      Index           =   4
      Left            =   2040
      TabIndex        =   16
      Top             =   2400
      Width           =   480
   End
   Begin VB.CommandButton Percent 
      Caption         =   "%"
      Height          =   480
      Left            =   2640
      TabIndex        =   17
      Top             =   2400
      Width           =   480
   End
   Begin VB.Label Readout 
      Alignment       =   1  'Right Justify
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "0."
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   120
      TabIndex        =   19
      Top             =   105
      Width           =   3000
   End
End
Attribute VB_Name = "main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Option Explicit
    
    Dim Op1, Op2                ' 预先输入操作数。
    Dim DecimalFlag As Integer  ' 小数点存在吗?
    Dim NumOps As Integer       ' 操作数个数。
    Dim LastInput               ' 指示上一次按键事件的类型。
    Dim OpFlag                  ' 指示未完成的操作。
    Dim TempReadout
    
    ' C (取消) 按钮的 Click 事件过程
    ' 重新设置显示并初始化变量。
    Private Sub Cancel_Click()
        
        Readout = Format(0, "0.")
        Op1 = 0
        Op2 = 0
        Form_Load
    
    End Sub
    
    ' CE (取消输入) 按钮的 Click 事件过程。
    Private Sub CancelEntry_Click()
        
        Readout = Format(0, "0.")
        DecimalFlag = False
        LastInput = "CE"
    
    End Sub
  
    ' 小数点 (.) 按钮的 Click 事件过程
    ' 如果上一次按键为运算符,初始化 readout 为 "0.";
    ' 否则显示时追加一个小数点。
    Private Sub Decimal_Click()
        
        If LastInput <> "NUMS" Then
            Readout = Format(0, "0.")
        End If
        DecimalFlag = True
        LastInput = "NUMS"
    
    End Sub
    
    ' 窗体的初始化过程
    ' 设置所有变量为其初始值。
    Private Sub Form_Load()
        
        DecimalFlag = False
        NumOps = 0
        LastInput = "NONE"
        OpFlag = ""
        Readout = Format(0, "0.")
        
    End Sub
        
    '改变数字的正负号
    Private Sub negcmd_Click()
        
        If LastInput <> "OPS" Or OpFlag = "=" Then
        If Left(Readout, 1) <> "-" Then
            Readout = "-" & Readout
        Else
            Readout = Right(Readout, Len(Readout) - 1)
        End If
        End If
        
    End Sub

    ' 数字键 (0-9) 的 Click 事件过程
    ' 向显示中的数追加新数。
    Private Sub Number_Click(Index As Integer)
        
        If LastInput <> "NUMS" Then
            Readout = Format(0, ".")
            DecimalFlag = False
        End If
        If DecimalFlag Then
            Readout = Readout + Number(Index).Caption
        Else
            Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
        End If
        LastInput = "NUMS"
    
    End Sub
    
    ' 运算符 (+, -, x, /, =) 的 Click 事件过程
    ' 如果接下来的按键是数字键,增加 NumOps。
    ' 如果有一个操作数,则设置 Op1。
    ' 如果有两个操作数,则将 Op1 设置为 Op1 与
    ' 当前输入字符串的运算结果,并显示结果。
    Private Sub Operator_Click(Index As Integer)
        
        TempReadout = Readout
        If LastInput <> "OPS" Then
            NumOps = NumOps + 1
        End If
        Select Case NumOps
            Case 0
            '什么也不做
            Case 1
            Op1 = Readout
            Case 2
            Op2 = TempReadout
            Select Case OpFlag
                Case "+"
                    Op1 = CDbl(Op1) + CDbl(Op2)
                Case "-"
                    Op1 = CDbl(Op1) - CDbl(Op2)
                Case "X"
                    Op1 = CDbl(Op1) * CDbl(Op2)
                Case "/"
                    If Op2 = 0 Then
                       MsgBox "除数不能为零", 48, "计算器"
                    Else
                       Op1 = CDbl(Op1) / CDbl(Op2)
                    End If
                Case "="
                    Op1 = CDbl(Op2)
                Case "%"
                    Op1 = CDbl(Op1) * CDbl(Op2)
                End Select
            Readout = Op1
            NumOps = 1
        End Select
        LastInput = "OPS"
        OpFlag = Operator(Index).Caption
            
    End Sub
    
    ' 百分比键 (%) 的 Click 事件过程
    Private Sub Percent_Click()
        
        If LastInput <> "OPS" Or OpFlag = "=" Then
            Readout = Readout / 100
            LastInput = "PER"
            DecimalFlag = True
        End If
    
    End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -