📄 calculator.frm
字号:
End
Begin VB.Menu Help
Caption = "Help"
Begin VB.Menu Helptopic
Caption = "Help Topics"
Enabled = 0 'False
End
Begin VB.Menu separator2
Caption = "-"
End
Begin VB.Menu About_me
Caption = "About Calculator"
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
Private operator As String ' These are "+, - , *, / "
Private screen1 As Double ' For digits used before operator " +, - , *, / "
Private screen2 As Double ' For digits used after operator " +, - , *, / "
''Private memory1 As Double
''Private memory2 As Double
Private memsux As Boolean
Private X As String
'<:-) :WARNING: Single letter Variables 'X' or 'Y' make code difficult to read as VB uses them in Mouse Events.
'<:-) :SUGGESTION: Change the variable name to (strX).
'<:-) If you are only using it as a For structures counter use a Dim instead
'<:-) (may cause local Dims to be marked as duplicates)
Private Sub About_me_Click()
On Error Resume Next
Load About_Calc
About_Calc.Show 0, Me
Me.Enabled = False
On Error GoTo 0
End Sub
Private Sub backg_Click()
On Error GoTo e
With cd1
.Filter = "Bitmap (*.bmp)|*.bmp|Jpeg (*.jpg)|*.jpg|Gif (*.gif)|*.gif|All Files (*.*)|*.*"
.ShowOpen
Image1.Picture = LoadPicture(.FileName)
End With 'cd1
display.BackColor = vbWhite
display.ForeColor = vbBlack
e:
If Err.Number = 481 Then
MsgBox "It's Not a picture", vbExclamation
End If
End Sub
Private Sub cmd_digits_Click(Index As Integer)
If display.Text = "0" Then
display.Text = cmd_digits(Index).Caption
Else 'NOT DISPLAY.TEXT...
display.Text = display.Text + cmd_digits(Index).Caption
End If
End Sub
Private Sub cmd_digits_MouseOver(Index As Integer)
cmd_digits(Index).ToolTipText = cmd_digits(Index).Caption
End Sub
Private Sub cmd_digits_MouseUp(Index As Integer, _
Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
'Private Sub cmd_digits_Click(Index As Integer)
'display.Caption = display.Caption + cmd_digits(Index).Caption
'End Sub
'Private Sub cmd_digits_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'Me.SetFocus
'End Sub
Private Sub cmdbackspace_Click()
If LenB(display.Text) = 0 Then
display.Text = "0"
Else 'NOT LENB(DISPLAY.TEXT)...
display.Text = Mid$(display.Text, 1, Len(display.Text) - 1)
End If
End Sub
Private Sub cmdbackspace_MouseOver()
cmdbackspace.ToolTipText = cmdbackspace.Caption
End Sub
Private Sub cmdbackspace_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdclear_MouseOver()
cmdclear.ToolTipText = "Clear All"
End Sub
Private Sub cmdclear_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
display.Text = "0"
screen1 = 0
screen2 = 0
operator = vbNullString
Me.SetFocus
If lbl_app.Text = "M" Then
lbl_app.Text = lbl_app.Text
lbl_app.ForeColor = vbRed
Else 'NOT LBL_APP.TEXT...
lbl_app.Text = vbNullString
End If
End Sub
Private Sub cmddivide_Click()
screen1 = Val(display.Text)
operator = "/"
display.Text = vbNullString
lbl_app.Text = "/"
lbl_app.ForeColor = vbRed
lbl_app.ToolTipText = "operator been used"
End Sub
Private Sub cmddivide_MouseOver()
cmddivide.ToolTipText = """/"" Division"
End Sub
Private Sub cmddivide_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdempty_MouseOver()
cmdempty.ToolTipText = "Clear Empty"
End Sub
Private Sub cmdempty_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
screen2 = 0
display.Text = "0"
Me.SetFocus
End Sub
Private Sub cmdequal_Click()
screen2 = Val(display.Text)
If operator = "+" Then
display.Text = (screen1 + screen2)
End If
If operator = "-" Then
display.Text = (screen1 - screen2)
End If
If operator = "/" Then
If screen2 <> 0 Then
display.Text = (screen1) / screen2
End If
End If
If operator = "x" Then
display.Text = (screen1 * screen2)
End If
'<:-) Auto-inserted With End...With Structure
With display
If .Text < 0 Then
If .Text > -1 Then
.Text = "-0" & Abs(.Text) 'Adds negative zero in display
End If
End If
End With 'display
'<:-) Auto-inserted With End...With Structure
With display
If .Text > 0 Then
If .Text < 1 Then
.Text = "0" & Abs(.Text) 'Adds zero in display
End If
End If
End With 'display
'screen1 = Val(display.Text)
End Sub
Private Sub cmdequal_MouseOver()
cmdequal.ToolTipText = "Equals to./ Answer"
End Sub
Private Sub cmdequal_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdmc_MouseOver()
cmdmc.ToolTipText = "Memory Clear"
End Sub
Private Sub cmdmc_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
tmp.Text = vbNullString
lbl_app.Text = vbNullString
End Sub
Private Sub cmdmemplus_Click()
If LenB(display.Text) = 0 Then
display.Text = display.Text
Else 'NOT LENB(DISPLAY.TEXT)...
display.SelStart = 0
display.SelLength = Len(display.Text)
Clipboard.Clear
Clipboard.SetText display.SelText
memsux = True
If memsux Then
lbl_app.Text = "M"
lbl_app.ForeColor = vbRed
End If
tmp.Text = vbNullString
tmp.SelText = Clipboard.GetText
End If
End Sub
Private Sub cmdmemplus_MouseOver()
cmdmemplus.ToolTipText = "Add Memory"
End Sub
Private Sub cmdmemplus_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdminus_Click()
screen1 = Val(display.Text)
operator = "-"
display.Text = vbNullString
lbl_app.Text = "-"
lbl_app.ForeColor = vbRed
lbl_app.ToolTipText = "operator been used"
End Sub
Private Sub cmdminus_MouseOver()
cmdminus.ToolTipText = """-"" Minus / Subtract"
End Sub
Private Sub cmdminus_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdmr_Click()
display.Text = tmp.Text
End Sub
Private Sub cmdmr_MouseOver()
cmdmr.ToolTipText = "Paste Memory"
End Sub
Private Sub cmdmr_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdms_Click()
If LenB(display.Text) = 0 Then
display.Text = display.Text
Else 'NOT LENB(DISPLAY.TEXT)...
display.SelStart = 0
display.SelLength = Len(display.Text)
Clipboard.Clear
Clipboard.SetText display.SelText
memsux = True
If memsux Then
lbl_app.Text = "M"
lbl_app.ForeColor = vbRed
End If
tmp.Text = vbNullString
tmp.SelText = Clipboard.GetText
End If
Command1.SetFocus
End Sub
Private Sub cmdms_MouseMove(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdms_MouseOver()
cmdms.ToolTipText = "Memory Select"
End Sub
Private Sub cmdmultiply_Click()
screen1 = Val(display.Text)
operator = "x"
display.Text = vbNullString
lbl_app.Text = "x"
lbl_app.ForeColor = vbRed
lbl_app.ToolTipText = "operator been used"
End Sub
Private Sub cmdmultiply_GotFocus()
Me.SetFocus
End Sub
Private Sub cmdmultiply_MouseOver()
cmdmultiply.ToolTipText = """x"" Multiply"
End Sub
Private Sub cmdmultiply_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdpercentage_Click()
screen2 = Val(display.Text)
If operator = "/" Then
If screen2 <> 0 Then
display.Text = (screen1 / 100) * screen2
If lbl_app.Text = "M" Then
lbl_app.Text = lbl_app.Text
Else 'NOT LBL_APP.TEXT...
lbl_app.Text = "%"
End If
End If
End If
End Sub
Private Sub cmdpercentage_MouseOver()
cmdpercentage.ToolTipText = "Percentage out of 100"
End Sub
Private Sub cmdpercentage_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdplus_Click()
screen1 = Val(display.Text)
operator = "+"
display.Text = vbNullString
lbl_app.Text = "+"
lbl_app.ForeColor = vbRed
lbl_app.ToolTipText = "operator been used"
End Sub
Private Sub cmdplus_MouseOver()
cmdplus.ToolTipText = """+"" Plus / Addition"
End Sub
Private Sub cmdplus_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdplusminus_Click()
display.Text = -Val(display.Text)
If display.Text < 0 Then
If display.Text > -1 Then
display.Text = "-0" & Abs(display.Text) '在计算时如果小于1那小数点前就没0
End If
End If
'<:-) Auto-inserted With End...With Structure
With display
If .Text > 0 Then
If .Text < 1 Then
.Text = "0" & Abs(.Text) '在计算时如果小于1那小数点前就没0
End If
End If
End With 'display
End Sub
Private Sub cmdplusminus_MouseOver()
cmdplusminus.ToolTipText = """+/-"" Plus Minus"
End Sub
Private Sub cmdplusminus_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdpoint_Click()
If InStr(display.Text, ".") Then
Else 'NOT INSTR(DISPLAY.TEXT,...
display.Text = display.Text & "." ' Adds point in display.
End If
End Sub
Private Sub cmdpoint_MouseOver()
cmdpoint.ToolTipText = """."" Point(Decimal) "
End Sub
Private Sub cmdpoint_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
Me.SetFocus
End Sub
Private Sub cmdreciprocal_Click()
If LenB(display.Text) = 0 Then
display.Text = vbNullString
Else 'NOT LENB(DISPLAY.TEXT)...
With display
If Val(.Text) <> 0 Then
.ToolTipText = 1 / .Text
.Text = 1 / Val(.Text)
End If
End With 'display
End If
Command1.SetFocus
End Sub
Private Sub cmdreciprocal_GotFocus()
Command1.SetFocus
End Sub
Private Sub cmdreciprocal_MouseOver()
cmdreciprocal.ToolTipText = "Reciprocal"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -