?? frmex.frm
字號(hào):
VERSION 5.00
Begin VB.Form Calculator
BackColor = &H00400000&
Caption = "四則計(jì)算器 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 = "關(guān)閉"
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 = "關(guān)于"
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 '操作數(shù)
Dim StrNum1, StrNum2 As String
Dim FirstNum As Boolean '判斷是否是數(shù)字開頭
Dim PointFlag As Boolean '判斷是否已有小數(shù)點(diǎn)
Dim RunSign As Integer '儲(chǔ)存運(yùn)算符號(hào)
Dim SignFlag As Boolean '判斷是否已有運(yùn)算符號(hào)
Dim equal As Double '運(yùn)算結(jié)果
Dim equalflag As Boolean '運(yùn)算結(jié)果有無標(biāo)志 因?yàn)橛?jì)算結(jié)果不能用退格按鈕
Dim OffSign As Boolean '計(jì)算器關(guān)閉標(biāo)志
Private Sub Command1_Click(Index As Integer)
If OffSign = False Then '計(jì)算器已打開
If Index = 16 Then '清除按鈕
Call ClearData
Else
Select Case Index
Case 0 To 9
If FirstNum Then '如果是第一個(gè)字符
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 '如果沒有小數(shù)點(diǎn)
If FirstNum Then
StrNum1 = "0."
FirstNum = False
Else
StrNum1 = StrNum1 + "."
End If
Else '已有小數(shù)點(diǎn)
Exit Sub
End If
PointFlag = True
txtShow.Text = StrNum1
Case 12 To 15 '+ - × ÷
FirstNum = True '使下一次可以輸入新數(shù)據(jù)
PointFlag = False '還原標(biāo)記值
If SignFlag Then '前面已有運(yùn)算符未運(yùn)算
Call Run
Else
SignFlag = True
StrNum2 = StrNum1 '把字符串1復(fù)制給字符串2
StrNum1 = "" '字符串1清空
End If
RunSign = Index - 11 '儲(chǔ)存鍵入的運(yùn)算符
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 '計(jì)算器已關(guān)閉
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 '開頭數(shù)字
PointFlag = False '小數(shù)點(diǎn)
RunSign = 0
SignFlag = False '無運(yùn)算符號(hào)
equalflag = False '無計(jì)算結(jié)果
OffSign = True '關(guān)閉
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 '計(jì)算結(jié)果后復(fù)位標(biāo)志
Exit Sub
Err:
txtShow.Text = "除數(shù)不能為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
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -