\'In the name of ALLAH
\'Name : Muhammad Azri bin Jasni @ Abdul Rani
\'ID : 2009147897
\'Group: CS1105A
\'Features:
\' Have Digits buttons, cmd# (# represent 0-9)
\' Operators buttons,cmdAdd,cmdMinus,cmdMulti,cmdDivide
\' Decimal Point, cmdDot
\' Calculate button, cmdEnter
\' Result display area, txtResult
\' Clear Button/CLEAR, cmdClear
\' Close button/BYE, cmdExit
\' Divide by Zero error will be told in the result display area (Math Error)
\' Multiple click of operator button doesn\'t change the memory of first operator pressed
\'Known Bugs:
\' Other errors is not handled yet.
\' Didn \'t handle situation where decimal point button pressed for an existing double type answer
\' No limit of digits yet
Option Explicit
Dim result As Double
Dim memory As Double
Dim tempResult As Double
Dim operator As Integer \'0 for Default, 1 for Add, 2 for Minus, 3 for Multiply, 4 for Divide
Dim dotCounter As Integer
\'Numbers
Private Sub cmd0_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf operator <> 0 Then
txtResult.Text = "0"
ElseIf txtResult.Text <> "0" Then
txtResult.Text = txtResult.Text & "0"
End If
End Sub
Private Sub cmd1_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "1"
Else: txtResult.Text = txtResult.Text + "1"
End If
End Sub
Private Sub cmd2_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "2"
Else: txtResult.Text = txtResult.Text + "2"
End If
End Sub
Private Sub cmd3_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "3"
Else: txtResult.Text = txtResult.Text + "3"
End If
End Sub
Private Sub cmd4_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "4"
Else: txtResult.Text = txtResult.Text + "4"
End If
End Sub
Private Sub cmd5_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "5"
Else: txtResult.Text = txtResult.Text + "5"
End If
End Sub
Private Sub cmd6_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "6"
Else: txtResult.Text = txtResult.Text + "6"
End If
End Sub
Private Sub cmd7_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "7"
Else: txtResult.Text = txtResult.Text + "7"
End If
End Sub
Private Sub cmd8_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "8"
Else: txtResult.Text = txtResult.Text + "8"
End If
End Sub
Private Sub cmd9_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "0" Then
txtResult.Text = "9"
Else: txtResult.Text = txtResult.Text + "9"
End If
End Sub
\'Operators
Private Sub cmdAdd_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf operator <> 0 Then
Else:
memory = txtResult.Text
txtResult.Text = ""
operator = 1
End If
End Sub
Private Sub cmdMinus_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf operator <> 0 Then
Else:
memory = txtResult.Text
txtResult.Text = ""
operator = 2
End If
End Sub
Private Sub cmdMulti_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf operator <> 0 Then
Else:
memory = txtResult.Text
txtResult.Text = ""
operator = 3
End If
End Sub
Private Sub cmdDivide_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf operator <> 0 Then
Else:
memory = txtResult.Text
txtResult.Text = ""
operator = 4
End If
End Sub
Private Sub cmdClear_Click()
result = 0
txtResult.Text = 0
operator = 0
tempResult = 0
End Sub
Private Sub cmdDot_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
ElseIf dotCounter = 0 Then
txtResult.Text = txtResult.Text + "."
dotCounter = 1
End If
End Sub
Private Sub cmdEnter_Click()
If txtResult.Text = "Math Error" Then
txtResult.Text = "Press Clear to Continue"
ElseIf txtResult.Text = "Press Clear to Continue" Then
txtResult.Text = "Press Clear to Continue"
Else
tempResult = txtResult.Text
If operator = 0 Then
txtResult.Text = tempResult
ElseIf operator = 1 Then
txtResult.Text = memory + tempResult
ElseIf operator = 2 Then
txtResult.Text = memory - tempResult
ElseIf operator = 3 Then
txtResult.Text = memory * tempResult
ElseIf operator = 4 Then
If tempResult = 0 Then
txtResult.Text = "Math Error"
Else:
txtResult.Text = memory / tempResult
End If
End If
End If
memory = 0
operator = 0
dotCounter = 0
End Sub
\'Exit
Private Sub cmdExit_Click()
End
End Sub