📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "计算器"
ClientHeight = 3375
ClientLeft = 60
ClientTop = 345
ClientWidth = 3300
LinkTopic = "Form1"
ScaleHeight = 3375
ScaleWidth = 3300
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtDisplay
Alignment = 1 'Right Justify
BackColor = &H00FFFF00&
Enabled = 0 'False
BeginProperty Font
Name = "Times New Roman"
Size = 24
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FFFFFF&
Height = 615
Left = 15
TabIndex = 18
Top = 0
Width = 3090
End
Begin VB.CommandButton cmdNumber
Caption = "0"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 0
TabIndex = 17
Top = 2715
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "1"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 1
Left = 0
TabIndex = 16
Top = 915
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "2"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 2
Left = 600
TabIndex = 15
Top = 915
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "3"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 3
Left = 1200
TabIndex = 14
Top = 915
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "4"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 4
Left = 0
TabIndex = 13
Top = 1515
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "5"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 5
Left = 600
TabIndex = 12
Top = 1515
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "6"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 6
Left = 1200
TabIndex = 11
Top = 1515
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "7"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 7
Left = 0
TabIndex = 10
Top = 2115
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "8"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 8
Left = 585
TabIndex = 9
Top = 2100
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "9"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 9
Left = 1200
TabIndex = 8
Top = 2115
Width = 495
End
Begin VB.CommandButton cmdNumber
Caption = "."
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 10
Left = 585
TabIndex = 7
Top = 2715
Width = 495
End
Begin VB.CommandButton cmdPN
Caption = "+/-"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1200
TabIndex = 6
Top = 2715
Width = 495
End
Begin VB.CommandButton cmdCalc
Caption = "+"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 2010
TabIndex = 5
Top = 1605
Width = 510
End
Begin VB.CommandButton cmdCalc
Caption = "-"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 1
Left = 2595
TabIndex = 4
Top = 1575
Width = 510
End
Begin VB.CommandButton cmdCalc
Caption = "*"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 2
Left = 2055
TabIndex = 3
Top = 2175
Width = 510
End
Begin VB.CommandButton cmdCalc
Caption = "/"
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 480
Index = 3
Left = 2580
TabIndex = 2
Top = 2175
Width = 510
End
Begin VB.CommandButton cmdEqual
Caption = "="
BeginProperty Font
Name = "Times New Roman"
Size = 15.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 450
Left = 2040
TabIndex = 1
Top = 2760
Width = 1035
End
Begin VB.CommandButton cmdBack
Caption = "-->"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1995
TabIndex = 0
Top = 900
Width = 1095
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 str1 As String '以字符串形式存放第一个操作数
Dim str2 As String '以字符串形式存放第二个操作数
Dim strtemp As String '存放临时字符串
Dim blnStatus As Boolean 'False时,输入第一个操作数;True时,输入第二个操作数
Dim intOperate As Integer '存放运算类型:1加、2减、3乘、4除
Private Sub cmdNumber_Click(Index As Integer)
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Index < 10 Then '输入数字
strtemp = strtemp + CStr(Index)
Else '输入小数点
If InStr(strtemp, ".") = 0 Then strtemp = strtemp + "." '阻止出现两个小数点
End If
If Len(strtemp) > 1 And Left(strtemp, 1) = "0" And Mid(strtemp, 2, 1) <> "." Then
strtemp = Right(strtemp, Len(strtemp) - 1) '删除数开始多余的0
End If
txtDisplay.Text = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub
Private Sub cmdBack_Click() '去掉最右边的一个字符
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 Then strtemp = Left(strtemp, Len(strtemp) - 1) '去掉操作数最后一个字符
txtDisplay = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub
Private Sub cmdPN_Click() '改变正负号
If Not blnStatus Then strtemp = str1 Else strtemp = str2
If Len(strtemp) > 0 And Left(strtemp, 1) = "-" Then
strtemp = Right(strtemp, Len(strtemp) - 1) '去掉负号
Else
strtemp = "-" & strtemp '添加负号
End If
txtDisplay = strtemp
If Not blnStatus Then str1 = strtemp Else str2 = strtemp
End Sub
Private Sub cmdCalc_Click(Index As Integer)
str2 = "" '按下运算符时,把第二个字符串清空
txtDisplay.Text = ""
blnStatus = True '为输入第二个字符串作准备
intOperate = Index
End Sub
Private Sub cmdEqual_Click() '单击了等号键时进行运算
If Len(Trim(str1)) = 0 Or Len(Trim(str2)) = 0 Then
blnStatus = False
Exit Sub '任一字符串为空,则不进行计算
End If
Dim dbl1 As Double
Dim dbl2 As Double
dbl1 = Val(str1) '把字符串转换为数值算
dbl2 = Val(str2)
Select Case intOperate '进行不同的运算
Case 0
txtDisplay.Text = dbl1 + dbl2
Case 1
txtDisplay.Text = dbl1 - dbl2
Case 2
txtDisplay.Text = dbl1 * dbl2
Case 3
If dbl2 = 0 Then
MsgBox "除数不能为零!", 16, "计算器"
Exit Sub
End If
txtDisplay.Text = dbl1 / dbl2
End Select
blnStatus = False '为输入第一个操作数作准备
str1 = "" '清空两个字符串
str2 = ""
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -