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

📄 计算器.frm

📁 上传的包含两个文件
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4830
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4320
   LinkTopic       =   "Form1"
   Picture         =   "计算器.frx":0000
   ScaleHeight     =   4830
   ScaleWidth      =   4320
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "删除"
      Height          =   375
      Index           =   15
      Left            =   1560
      TabIndex        =   16
      Top             =   3120
      Width           =   735
   End
   Begin VB.CommandButton Command1 
      Caption         =   "="
      Height          =   375
      Index           =   14
      Left            =   1440
      TabIndex        =   15
      Top             =   2520
      Width           =   975
   End
   Begin VB.CommandButton Command1 
      Caption         =   "/"
      Height          =   375
      Index           =   13
      Left            =   2640
      TabIndex        =   14
      Top             =   1800
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "*"
      Height          =   375
      Index           =   12
      Left            =   2040
      TabIndex        =   13
      Top             =   1800
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "-"
      Height          =   375
      Index           =   11
      Left            =   1320
      TabIndex        =   12
      Top             =   1800
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "+"
      Height          =   375
      Index           =   10
      Left            =   720
      TabIndex        =   11
      Top             =   1800
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "9"
      Height          =   375
      Index           =   9
      Left            =   2880
      TabIndex        =   10
      Top             =   1320
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "8"
      Height          =   375
      Index           =   8
      Left            =   2280
      TabIndex        =   9
      Top             =   1320
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "7"
      Height          =   375
      Index           =   7
      Left            =   1680
      TabIndex        =   8
      Top             =   1320
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "6"
      Height          =   375
      Index           =   6
      Left            =   1080
      TabIndex        =   7
      Top             =   1320
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "5"
      Height          =   375
      Index           =   5
      Left            =   480
      TabIndex        =   6
      Top             =   1320
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "4"
      Height          =   375
      Index           =   4
      Left            =   2880
      TabIndex        =   5
      Top             =   840
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "3"
      Height          =   375
      Index           =   3
      Left            =   2280
      TabIndex        =   4
      Top             =   840
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "2"
      Height          =   375
      Index           =   2
      Left            =   1680
      TabIndex        =   3
      Top             =   840
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "1"
      Height          =   375
      Index           =   1
      Left            =   1080
      TabIndex        =   2
      Top             =   840
      Width           =   375
   End
   Begin VB.CommandButton Command1 
      Caption         =   "0"
      Height          =   375
      Index           =   0
      Left            =   480
      TabIndex        =   1
      Top             =   840
      Width           =   375
   End
   Begin VB.TextBox Text1 
      Height          =   495
      Left            =   240
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   120
      Width           =   3615
   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, num2, equal As Double
Dim strnum1, strnum2 As String
Dim firstnum As Boolean
Dim signflag As Boolean
Dim runsign As Integer

Private Sub Command1_Click(Index As Integer)
If Index = 15 Then
   Call cleardata
Else
   Select Case Index
   Case 0 To 9
       If firstnum Then
          strnum1 = Right(Str(Index), 1)
          firstnum = False
       Else
          If Len(strnum1) <= 20 Then
          strnum1 = strnum1 + Right(Str(Index), 1)
          End If
       End If
       Text1.Text = strnum1
   Case 10 To 13
       firstnum = True
       If signflag Then
          Call run
       Else
          signflag = True
          strnum2 = strnum1
          strnum1 = " "
       End If
       runsign = Index - 9
   Case 14
   If Not signflag Then
       equal = Text1.Text
       firstnum = True
   Else
       Call run
       signflag = False
   End If
End Select
End If
End Sub

Private Sub Form_Load()
num1 = 0
num2 = 0
strnum1 = " "
strnum2 = " "
firstnum = True
signflag = False
End Sub
Public Sub run()
num1 = Val(strnum2)
num2 = Val(strnum1)
Select Case runsign
   Case 1
        equal = num1 + num2
   Case 2
        equal = num1 - num2
   Case 3
        equal = num1 * num2
   Case 4
        equal = num1 / num2
End Select
strnum2 = Trim(Str(equal))
If Left(strnum2, 1) = "." Then
    strnum2 = "0" + strnum2
ElseIf Left(strnum2, 2) = "-." Then
    strnum2 = "-0." + Right(strnum2, Len(strnum2) - 2)
End If
strnum1 = strnum2
Text1.Text = strnum2
firstnum = True
Exit Sub
err:
    Text1.Text = "除数不能为0"
End Sub
Public Sub cleardata()
num1 = 0
num2 = 0
Text1.Text = " "
strnum1 = " "
strnum2 = " "
firstnum = True
signflag = False
End Sub

⌨️ 快捷键说明

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