📄 frmex.frm
字号:
VERSION 5.00
Begin VB.Form Calculator
BackColor = &H00400000&
Caption = "四则计算器 www.vczx.com"
ClientHeight = 3855
ClientLeft = 165
ClientTop = 735
ClientWidth = 3870
Icon = "frmEx.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3855
ScaleWidth = 3870
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "="
Height = 255
Index = 18
Left = 2760
Style = 1 'Graphical
TabIndex = 21
Top = 3360
Width = 855
End
Begin VB.CommandButton Command2
BackColor = &H000000FF&
Caption = "关闭"
Height = 375
Index = 1
Left = 1200
Style = 1 'Graphical
TabIndex = 20
Top = 840
Width = 735
End
Begin VB.CommandButton Command2
BackColor = &H00FF0000&
Caption = "打开"
Height = 375
Index = 0
Left = 240
Style = 1 'Graphical
TabIndex = 19
Top = 840
Width = 735
End
Begin VB.CommandButton Command1
BackColor = &H00FF8080&
Caption = "退格"
Height = 375
Index = 17
Left = 2160
MaskColor = &H00FF8080&
Style = 1 'Graphical
TabIndex = 18
Top = 840
Width = 615
End
Begin VB.CommandButton Command1
BackColor = &H00FF8080&
Caption = "清除"
Height = 375
Index = 16
Left = 3000
MaskColor = &H00FF8080&
Style = 1 'Graphical
TabIndex = 17
Top = 840
Width = 615
End
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "÷"
Height = 255
Index = 15
Left = 2760
Style = 1 'Graphical
TabIndex = 16
Top = 2880
Width = 855
End
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "×"
Height = 255
Index = 14
Left = 2760
MaskColor = &H0080C0FF&
Style = 1 'Graphical
TabIndex = 15
Top = 2400
Width = 855
End
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "-"
Height = 255
Index = 13
Left = 2760
Style = 1 'Graphical
TabIndex = 14
Top = 1920
Width = 855
End
Begin VB.CommandButton Command1
BackColor = &H0080C0FF&
Caption = "+"
Height = 255
Index = 12
Left = 2760
Style = 1 'Graphical
TabIndex = 13
Top = 1440
Width = 855
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "+/-"
Height = 375
Index = 11
Left = 1920
Style = 1 'Graphical
TabIndex = 12
Top = 3240
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "."
Height = 375
Index = 10
Left = 1080
Style = 1 'Graphical
TabIndex = 11
Top = 3240
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "9"
Height = 375
Index = 9
Left = 1920
Style = 1 'Graphical
TabIndex = 10
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "8"
Height = 375
Index = 8
Left = 1080
Style = 1 'Graphical
TabIndex = 9
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "7"
Height = 375
Index = 7
Left = 240
Style = 1 'Graphical
TabIndex = 8
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "6"
Height = 375
Index = 6
Left = 1920
Style = 1 'Graphical
TabIndex = 7
Top = 2040
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "5"
Height = 375
Index = 5
Left = 1080
Style = 1 'Graphical
TabIndex = 6
Top = 2040
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "4"
Height = 375
Index = 4
Left = 240
Style = 1 'Graphical
TabIndex = 5
Top = 2040
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "3"
Height = 375
Index = 3
Left = 1920
Style = 1 'Graphical
TabIndex = 4
Top = 2640
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "2"
Height = 375
Index = 2
Left = 1080
Style = 1 'Graphical
TabIndex = 3
Top = 2640
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "1"
Height = 375
Index = 1
Left = 240
Style = 1 'Graphical
TabIndex = 2
Top = 2640
Width = 495
End
Begin VB.CommandButton Command1
BackColor = &H00FFC0C0&
Caption = "0"
Height = 375
Index = 0
Left = 240
Style = 1 'Graphical
TabIndex = 1
Top = 3240
Width = 495
End
Begin VB.TextBox txtShow
Alignment = 1 'Right Justify
BackColor = &H0000FF00&
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 0
Top = 240
Width = 3375
End
Begin VB.Menu mnuHelp
Caption = "帮助"
Begin VB.Menu mnuAbout
Caption = "关于"
Shortcut = ^A
End
Begin VB.Menu mnuExit
Caption = "退出"
Shortcut = ^E
End
End
End
Attribute VB_Name = "Calculator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Num1, Num2 As Double '操作数
Dim StrNum1, StrNum2 As String
Dim FirstNum As Boolean '判断是否是数字开头
Dim PointFlag As Boolean '判断是否已有小数点
Dim RunSign As Integer '储存运算符号
Dim SignFlag As Boolean '判断是否已有运算符号
Dim equal As Double '运算结果
Dim equalflag As Boolean '运算结果有无标志 因为计算结果不能用退格按钮
Dim OffSign As Boolean '计算器关闭标志
Private Sub Command1_Click(Index As Integer)
If OffSign = False Then '计算器已打开
If Index = 16 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) <= 25 Then
StrNum1 = StrNum1 + Right(Str(Index), 1)
End If
End If
txtShow.Text = StrNum1
Case 10
If Not PointFlag Then '如果没有小数点
If FirstNum Then
StrNum1 = "0."
FirstNum = False
Else
StrNum1 = StrNum1 + "."
End If
Else '已有小数点
Exit Sub
End If
PointFlag = True
txtShow.Text = StrNum1
Case 12 To 15 '+ - × ÷
FirstNum = True '使下一次可以输入新数据
PointFlag = False '还原标记值
If SignFlag Then '前面已有运算符未运算
Call Run
Else
SignFlag = True
StrNum2 = StrNum1 '把字符串1复制给字符串2
StrNum1 = "" '字符串1清空
End If
RunSign = Index - 11 '储存键入的运算符
Case 11 '+/-
If txtShow.Text <> "0" And txtShow.Text <> "0." Then
If Left(txtShow.Text, 1) = "-" Then
txtShow.Text = Right(txtShow.Text, Len(txtShow.Text) - 1)
Else
txtShow.Text = "-" & txtShow.Text
End If
End If
StrNum1 = txtShow.Text
Case 16 '清除按钮
Call ClearData
Case 17 '退格
If Not equalflag And txtShow.Text <> "" And txtShow.Text <> "0." Then
txtShow.Text = Left(txtShow.Text, Len(txtShow.Text) - 1)
StrNum1 = txtShow.Text
End If
Case 18 '=
If Not SignFlag Then
equal = txtShow.Text
FirstNum = True
PointFlag = False
equalflag = True
Else
Call Run
SignFlag = False
equalflag = True
End If
End Select
End If
Else
OffSign = True '计算器已关闭
Exit Sub
End If
End Sub
Private Sub Command2_Click(Index As Integer)
Select Case Index
Case 0
OffSign = False
txtShow.Text = "0."
Command2(0).Enabled = False
Command2(1).Enabled = True
Case 1
OffSign = True
txtShow.Text = ""
FirstNum = True
Command2(1).Enabled = False
Command2(0).Enabled = True
End Select
End Sub
Private Sub Form_Load()
Me.Top = 3500
Me.Left = 5500
Num1 = 0
Num2 = 0
StrNum1 = ""
StrNum2 = ""
FirstNum = True '开头数字
PointFlag = False '小数点
RunSign = 0
SignFlag = False '无运算符号
equalflag = False '无计算结果
OffSign = True '关闭
Command2(0).Enabled = True
Command2(1).Enabled = False
End Sub
Public Sub Run()
Dim ch As String
Num1 = Val(StrNum2)
Num2 = Val(StrNum1)
On Error GoTo Err:
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
txtShow.Text = StrNum2
FirstNum = True '计算结果后复位标志
Exit Sub
Err:
txtShow.Text = "除数不能为0"
OffSign = True
End Sub
Public Sub ClearData()
Num1 = 0
Num2 = 0
StrNum1 = ""
StrNum2 = ""
FirstNum = True
PointFlag = False
RunSign = 0
SignFlag = False
txtShow.Text = "0."
OffSign = False
equalflag = False
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show
End Sub
Private Sub mnuExit_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -