📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BackColor = &H8000000A&
BorderStyle = 1 'Fixed Single
Caption = "VB连算计算器"
ClientHeight = 3570
ClientLeft = 45
ClientTop = 615
ClientWidth = 3750
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3570
ScaleWidth = 3750
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command3
Caption = "_"
Height = 255
Left = 3480
TabIndex = 17
ToolTipText = "最小化窗口"
Top = 3240
Width = 255
End
Begin VB.CommandButton Command2
Caption = "OFF"
Height = 495
Left = 1080
TabIndex = 16
Top = 2640
Width = 735
End
Begin VB.CommandButton Command1
Caption = "="
Enabled = 0 'False
Height = 495
Index = 14
Left = 1920
TabIndex = 15
Top = 2640
Width = 735
End
Begin VB.CommandButton Command1
Caption = "/"
Enabled = 0 'False
Height = 495
Index = 13
Left = 2760
TabIndex = 14
Top = 2640
Width = 735
End
Begin VB.CommandButton Command1
Caption = "*"
Enabled = 0 'False
Height = 495
Index = 12
Left = 2760
TabIndex = 13
Top = 2040
Width = 735
End
Begin VB.CommandButton Command1
Caption = "-"
Enabled = 0 'False
Height = 495
Index = 11
Left = 2760
TabIndex = 12
Top = 1440
Width = 735
End
Begin VB.CommandButton Command1
Caption = "+"
Enabled = 0 'False
Height = 495
Index = 10
Left = 2760
TabIndex = 11
Top = 840
Width = 735
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 495
Index = 9
Left = 240
TabIndex = 10
Top = 2640
Width = 735
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 495
Index = 8
Left = 1920
TabIndex = 9
Top = 2040
Width = 735
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 495
Index = 7
Left = 1080
TabIndex = 8
Top = 2040
Width = 735
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 495
Index = 6
Left = 240
TabIndex = 7
Top = 2040
Width = 735
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 495
Index = 5
Left = 1920
TabIndex = 6
Top = 1440
Width = 735
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 495
Index = 4
Left = 1080
TabIndex = 5
Top = 1440
Width = 735
End
Begin VB.CommandButton Command1
Caption = "3"
Height = 495
Index = 3
Left = 240
TabIndex = 4
Top = 1440
Width = 735
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 495
Index = 2
Left = 1920
TabIndex = 3
Top = 840
Width = 735
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 495
Index = 1
Left = 1080
TabIndex = 2
Top = 840
Width = 735
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 495
Index = 0
Left = 240
TabIndex = 1
Top = 840
Width = 735
End
Begin VB.TextBox Text1
BackColor = &H80000009&
Enabled = 0 'False
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H0000FF00&
Height = 495
Left = 240
TabIndex = 0
Text = "Text1"
Top = 120
Width = 3255
End
Begin VB.Menu BZ
Caption = "帮助"
Begin VB.Menu SM
Caption = "使用说明"
Shortcut = {F1}
End
Begin VB.Menu GY
Caption = "关于"
Shortcut = ^O
End
Begin VB.Menu FW
Caption = "访问我的论坛"
Shortcut = ^W
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private o1 As Boolean '是否为第一个操作数.
Private N1, N2 As Single '两个操作数.
Private OPER% '保存运算符,1-4代表加减乘除.
Private sc$ '上次输入是操作数还是运算符,"C"表示操作数,"O"表示运算符.
Private dq$ '当前操作数字符串
Function YS(N1, N2, OPER) As Single
'On Error GoTo e1
Select Case OPER
Case 1
YS = N1 + N2
Case 2
YS = N1 - N2
Case 3
YS = N1 * N2
Case 4
If dq = 0 Then
MsgBox "除数不能为0"
On Error Resume Next
End If
YS = N1 / N2
'e1:
'MsgBox "除数不能为0"
End Select
End Function
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 To 9
If sc <> "C" Then
Command1(10).Enabled = True
Command1(11).Enabled = True
Command1(12).Enabled = True
Command1(13).Enabled = True
Command1(14).Enabled = True
dq = CStr(Index)
Else
dq = dq & Index
End If
sc = "C"
Text1.Text = dq
Case 10 To 13
sc = "O"
If o1 Then
N1 = CSng(dq)
o1 = False
Else
N2 = CSng(dq)
N1 = YS(N1, N2, OPER)
Text1.Text = N1
End If
OPER = Index - 9
Case 14
If sc = "C" Then
N2 = CSng(dq)
N1 = YS(N1, N2, OPER)
End If
MsgBox "最终结果是" & N1 & ",确定后可以重新开始运算"
Command1(10).Enabled = False
Command1(11).Enabled = False
Command1(12).Enabled = False
Command1(13).Enabled = False
Command1(14).Enabled = False
'Text1.Text = N1
Text1.Text = ""
o1 = True
sc = "O"
dq = ""
N1 = 0
N2 = 0
OPER = 0
End Select
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Form1.WindowState = 1
End Sub
Private Sub Form_Load()
For i = 0 To 9
Command1(i).Caption = i
Next i
Command1(10).Caption = "+"
Command1(11).Caption = "-"
Command1(12).Caption = "*"
Command1(13).Caption = "/"
Command1(14).Caption = "="
Text1.Text = ""
o1 = True
End Sub
Private Sub FW_Click()
MsgBox "我的网络技术论坛:http://zyzw.in126.com"
End Sub
Private Sub GY_Click()
MsgBox "刘海峰设计__程序爱好者加我QQ:54929735"
End Sub
Private Sub SM_Click()
MsgBox "实现简单运算,以后功能待加,请提出你的意见"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -