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

📄 计算器.frm

📁 一个简单的计算器
💻 FRM
字号:
VERSION 5.00
Begin VB.Form 计算器 
   Caption         =   "计算器"
   ClientHeight    =   3795
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5055
   LinkTopic       =   "Form2"
   ScaleHeight     =   3795
   ScaleWidth      =   5055
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command6 
      Caption         =   "sqr"
      Height          =   1695
      Left            =   4200
      TabIndex        =   21
      Top             =   1080
      Width           =   495
   End
   Begin VB.CommandButton Command5 
      Caption         =   "1/x"
      Height          =   495
      Left            =   3480
      TabIndex        =   20
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "0"
      Height          =   495
      Index           =   0
      Left            =   480
      TabIndex        =   19
      Top             =   1920
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "1"
      Height          =   495
      Index           =   1
      Left            =   1200
      TabIndex        =   18
      Top             =   1920
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "2"
      Height          =   495
      Index           =   2
      Left            =   1920
      TabIndex        =   17
      Top             =   1920
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "3"
      Height          =   495
      Index           =   3
      Left            =   2640
      TabIndex        =   16
      Top             =   1920
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "4"
      Height          =   495
      Index           =   4
      Left            =   480
      TabIndex        =   15
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "5"
      Height          =   495
      Index           =   5
      Left            =   1200
      TabIndex        =   14
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "6"
      Height          =   495
      Index           =   6
      Left            =   1920
      TabIndex        =   13
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "7"
      Height          =   495
      Index           =   7
      Left            =   2640
      TabIndex        =   12
      Top             =   2520
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "8"
      Height          =   495
      Index           =   8
      Left            =   480
      TabIndex        =   11
      Top             =   3120
      Width           =   615
   End
   Begin VB.CommandButton c 
      Caption         =   "9"
      Height          =   495
      Index           =   9
      Left            =   1200
      TabIndex        =   10
      Top             =   3120
      Width           =   615
   End
   Begin VB.CommandButton op 
      Caption         =   "+"
      Height          =   495
      Index           =   0
      Left            =   480
      TabIndex        =   9
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton op 
      Caption         =   "-"
      Height          =   495
      Index           =   1
      Left            =   1200
      TabIndex        =   8
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton op 
      Caption         =   "*"
      Height          =   495
      Index           =   2
      Left            =   1920
      TabIndex        =   7
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton op 
      Caption         =   "/"
      Height          =   495
      Index           =   3
      Left            =   2640
      TabIndex        =   6
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton Command1 
      Caption         =   "="
      Height          =   495
      Left            =   3480
      TabIndex        =   5
      Top             =   3120
      Width           =   1215
   End
   Begin VB.CommandButton dot 
      Caption         =   "."
      Height          =   495
      Left            =   1920
      TabIndex        =   4
      Top             =   3120
      Width           =   615
   End
   Begin VB.CommandButton Command2 
      Caption         =   "+/-"
      Height          =   495
      Left            =   2640
      TabIndex        =   3
      Top             =   3120
      Width           =   615
   End
   Begin VB.CommandButton Command3 
      Caption         =   "c"
      Height          =   495
      Left            =   3360
      TabIndex        =   2
      Top             =   1080
      Width           =   615
   End
   Begin VB.CommandButton Command4 
      Caption         =   "back"
      Height          =   495
      Left            =   3480
      TabIndex        =   1
      Top             =   1920
      Width           =   615
   End
   Begin VB.Label L 
      Alignment       =   1  'Right Justify
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Height          =   615
      Left            =   480
      TabIndex        =   0
      Top             =   240
      Width           =   4095
   End
End
Attribute VB_Name = "计算器"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim a As Single
Dim b As Single
Dim ops As String
Dim jsl As Boolean

Private Sub Command1_Click()
Dim t As Single
b = Val(L.Caption)
Select Case ops
Case "+"
t = a + b
Case "-"
t = a - b
Case "*"
t = a * b
Case "/"
t = a / b
End Select
L.Caption = t
jsl = True

End Sub

Private Sub c_Click(Index As Integer)
If jsl = True Then L.Caption = ""
jsl = False
L.Caption = L.Caption & c(Index).Caption

End Sub



Private Sub Command2_Click()
L.Caption = -Val(L.Caption)
End Sub

Private Sub Command3_Click()
L.Caption = ""

End Sub

Private Sub Command4_Click()
If L.Caption <> "" Then
L.Caption = Left(L.Caption, Len(L.Caption) - 1)
End If



End Sub

Private Sub Command5_Click()
L.Caption = 1 / Val(L.Caption)
jsl = True
End Sub

Private Sub Command6_Click()
L.Caption = Sqr(Val(L.Caption))
jsl = True
End Sub

Private Sub dot_Click()
If jsl = True Then
L.Caption = ""
jsl = False
End If
L.Caption = L.Caption & "."
L.Caption = Format(Val(L.Caption), "0.#")
dot.Enabled = True


End Sub

Private Sub op_Click(Index As Integer)
dot.Enabled = True
a = Val(L.Caption)
ops = op(Index).Caption
L.Caption = ""
End Sub

⌨️ 快捷键说明

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