Calculator Project Image-1 |
Form Design:
Form = 1
Command Button = 19
Label = 1
Properties Set:
Object | Property | Settings |
Form1 | Name Caption Height Width BackColor BorderStyle | frmCALCULATOR Calculator 5310 5640 &H00FF8080& 4 – Fixed ToolWindow |
Command1 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 0 480 960 120 2040 8 0 0 |
Command2 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 1 480 480 120 1560 8 1 1 |
Command3 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 2 480 480 600 1560 8 2 2 |
Command4 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 3 480 480 1080 1560 8 3 3 |
Command5 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 4 480 480 120 1080 8 4 4 |
Command6 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 5 480 480 600 1080 8 5 5 |
Command7 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 6 480 480 1080 1080 8 6 6 |
Command8 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 7 480 480 120 600 8 7 7 |
Command9 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 8 480 480 600 600 8 8 8 |
Command10 | Name Caption Height Width Left Top FontSize Index ToolTipText | Number 9 480 480 1080 600 8 9 9 |
Command11 | Name Caption Height Width Left Top FontSize ToolTipText | Decimal . 480 480 1080 2040 8 Decimal |
Command12 | Name Caption Height Width Left Top FontSize Index ToolTipText | Operator = 480 480 1800 2055 8 4 Equals |
Command13 | Name Caption Height Width Left Top FontSize ToolTipText | Percent % 480 480 2280 2055 8 Percent |
Command14 | Name Caption Height Width Left Top FontSize Index ToolTipText | Operator X 480 480 1800 1560 8 2 Multiply |
Command15 | Name Caption Height Width Left Top FontSize Index ToolTipText | Operator / 480 480 2280 1560 8 0 Divide |
Command16 | Name Caption Height Width Left Top FontSize Index ToolTipText | Operator + 480 480 1800 1095 8 1 Add |
Command17 | Name Caption Height Width Left Top FontSize Index ToolTipText | Operator - 480 480 2280 1095 8 3 Subtract |
Command18 | Name Caption Height Width Left Top FontSize ToolTipText | Cancel C 480 480 1800 615 8 Clear |
Command19 | Name Caption Height Width Left Top FontSize ToolTipText | CancelEntry CE 480 480 2280 600 8 Cancel Entry |
Label1 | Name Caption Alignment BackColor ForeColor BorderStyle Height Width Left Top FontName FontSize FontStyle | Readout 0. 1 – 1 Right Justify &H00FFFFFF& &H00000000& 1 – Fixed Single 360 2640 120 120 Times New Roman 12 Bold |
(General)
Option Explicit
Dim Op1, Op2 ' Previously input operand.
Dim DecimalFlag As Integer ' Decimal point present yet?
Dim NumOps As Integer ' Number of operands.
Dim LastInput ' Indicate type of last keypress event.
Dim OpFlag ' Indicate pending operation.
Dim TempReadout
' Click event procedure for C (cancel) key.
' Reset the display and initializes variables.
Private Sub Cancel_Click()
Readout = Format(0, "0.")
Op1 = 0
Op2 = 0
Form_Load
End Sub
' Click event procedure for CE (cancel entry) key.
Private Sub CancelEntry_Click()
Readout = Format(0, "0.")
DecimalFlag = False
LastInput = "CE"
End Sub
' Click event procedure for decimal point (.) key.
' If last keypress was an operator, initialize
' readout to "0." Otherwise, append a decimal
' point to the display.
Private Sub Decimal_Click()
If LastInput = "NEG" Then
Readout = Format(0, "-0.")
ElseIf LastInput <> "NUMS" Then
Readout = Format(0, "0.")
End If
DecimalFlag = True
LastInput = "NUMS"
End Sub
' Initialization routine for the form.
' Set all variables to initial values.
Private Sub Form_Load()
DecimalFlag = False
NumOps = 0
LastInput = "NONE"
OpFlag = " "
Readout = Format(0, "0.")
'Decimal.Caption = Format(0, ".")
End Sub
' Click event procedure for number keys (0-9).
' Append new number to the number in the display.
Private Sub Number_Click(Index As Integer)
If LastInput <> "NUMS" Then
Readout = Format(0, ".")
DecimalFlag = False
End If
If DecimalFlag Then
Readout = Readout + Number(Index).Caption
Else
Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
End If
If LastInput = "NEG" Then Readout = "-" & Readout
LastInput = "NUMS"
End Sub
' Click event procedure for operator keys (+, -, x, /, =).
' If the immediately preceeding keypress was part of a
' number, increments NumOps. If one operand is present,
' set Op1. If two are present, set Op1 equal to the
' result of the operation on Op1 and the current
' input string, and display the result.
Private Sub Operator_Click(Index As Integer)
TempReadout = Readout
If LastInput = "NUMS" Then
NumOps = NumOps + 1
End If
Select Case NumOps
Case 0
If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
Readout = "-" & Readout
LastInput = "NEG"
End If
Case 1
Op1 = Readout
If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
Readout = "-"
LastInput = "NEG"
End If
Case 2
Op2 = TempReadout
Select Case OpFlag
Case "+"
Op1 = CDbl(Op1) + CDbl(Op2)
Case "-"
Op1 = CDbl(Op1) - CDbl(Op2)
Case "X"
Op1 = CDbl(Op1) * CDbl(Op2)
Case "/"
If Op2 = 0 Then
MsgBox "Can't divide by zero", 48, "Calculator"
Else
Op1 = CDbl(Op1) / CDbl(Op2)
End If
Case "="
Op1 = CDbl(Op2)
Case "%"
Op1 = CDbl(Op1) * CDbl(Op2)
End Select
Readout = Op1
NumOps = 1
End Select
If LastInput <> "NEG" Then
LastInput = "OPS"
OpFlag = Operator(Index).Caption
End If
End Sub
' Click event procedure for percent key (%).
' Compute and display a percentage of the first operand.
Private Sub Percent_Click()
Readout = Readout / 100
LastInput = "Ops"
OpFlag = "%"
NumOps = NumOps + 1
DecimalFlag = True
End Sub
Calculator Project Image-4 |
Calculator Project Image-5 |
Calculator Project Image-6 |
Calculator Project Image-7 |
Calculator Project Image-8 |
Calculator Project Image-9 |
Calculator Project Image-10 |
Calculator Project Image-11 |
0 Comments
Thank you for your Comment.