document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. \'In the name of ALLAH
  2. \'Name : Muhammad Azri bin Jasni @ Abdul Rani
  3. \'ID   : 2009147897
  4. \'Group: CS1105A
  5. \'Features:
  6. \'      Have Digits buttons, cmd# (# represent 0-9)
  7. \'      Operators buttons,cmdAdd,cmdMinus,cmdMulti,cmdDivide
  8. \'      Decimal Point, cmdDot
  9. \'      Calculate button, cmdEnter
  10. \'      Result display area, txtResult
  11. \'      Clear Button/CLEAR, cmdClear
  12. \'      Close button/BYE, cmdExit
  13. \'      Divide by Zero error will be told in the result display area (Math Error)
  14. \'      Multiple click of operator button doesn\'t change the memory of first operator pressed
  15. \'Known Bugs:
  16. \'      Other errors is not handled yet.
  17. \'      Didn \'t handle situation where decimal point button pressed for an existing double type answer
  18. \'      No limit of digits yet
  19. Option Explicit
  20. Dim result As Double
  21. Dim memory As Double
  22. Dim tempResult As Double
  23. Dim operator As Integer \'0 for Default, 1 for Add, 2 for Minus, 3 for Multiply, 4 for Divide
  24. Dim dotCounter As Integer
  25.  
  26. \'Numbers
  27. Private Sub cmd0_Click()
  28.     If txtResult.Text = "Math Error" Then
  29.         txtResult.Text = "Press Clear to Continue"
  30.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  31.         txtResult.Text = "Press Clear to Continue"
  32.     ElseIf operator <> 0 Then
  33.         txtResult.Text = "0"
  34.     ElseIf txtResult.Text <> "0" Then
  35.         txtResult.Text = txtResult.Text & "0"
  36.     End If
  37. End Sub
  38.  
  39. Private Sub cmd1_Click()
  40.     If txtResult.Text = "Math Error" Then
  41.         txtResult.Text = "Press Clear to Continue"
  42.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  43.         txtResult.Text = "Press Clear to Continue"
  44.     ElseIf txtResult.Text = "0" Then
  45.         txtResult.Text = "1"
  46.     Else: txtResult.Text = txtResult.Text + "1"
  47.     End If
  48. End Sub
  49.  
  50. Private Sub cmd2_Click()
  51.     If txtResult.Text = "Math Error" Then
  52.         txtResult.Text = "Press Clear to Continue"
  53.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  54.         txtResult.Text = "Press Clear to Continue"
  55.     ElseIf txtResult.Text = "0" Then
  56.         txtResult.Text = "2"
  57.     Else: txtResult.Text = txtResult.Text + "2"
  58.     End If
  59. End Sub
  60.  
  61. Private Sub cmd3_Click()
  62.     If txtResult.Text = "Math Error" Then
  63.         txtResult.Text = "Press Clear to Continue"
  64.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  65.         txtResult.Text = "Press Clear to Continue"
  66.     ElseIf txtResult.Text = "0" Then
  67.         txtResult.Text = "3"
  68.     Else: txtResult.Text = txtResult.Text + "3"
  69.     End If
  70. End Sub
  71.  
  72. Private Sub cmd4_Click()
  73.     If txtResult.Text = "Math Error" Then
  74.         txtResult.Text = "Press Clear to Continue"
  75.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  76.         txtResult.Text = "Press Clear to Continue"
  77.     ElseIf txtResult.Text = "0" Then
  78.         txtResult.Text = "4"
  79.     Else: txtResult.Text = txtResult.Text + "4"
  80.     End If
  81. End Sub
  82.  
  83. Private Sub cmd5_Click()
  84.     If txtResult.Text = "Math Error" Then
  85.         txtResult.Text = "Press Clear to Continue"
  86.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  87.         txtResult.Text = "Press Clear to Continue"
  88.     ElseIf txtResult.Text = "0" Then
  89.         txtResult.Text = "5"
  90.     Else: txtResult.Text = txtResult.Text + "5"
  91.     End If
  92. End Sub
  93.  
  94. Private Sub cmd6_Click()
  95.     If txtResult.Text = "Math Error" Then
  96.         txtResult.Text = "Press Clear to Continue"
  97.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  98.         txtResult.Text = "Press Clear to Continue"
  99.     ElseIf txtResult.Text = "0" Then
  100.         txtResult.Text = "6"
  101.     Else: txtResult.Text = txtResult.Text + "6"
  102.     End If
  103. End Sub
  104.  
  105. Private Sub cmd7_Click()
  106.     If txtResult.Text = "Math Error" Then
  107.         txtResult.Text = "Press Clear to Continue"
  108.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  109.         txtResult.Text = "Press Clear to Continue"
  110.     ElseIf txtResult.Text = "0" Then
  111.         txtResult.Text = "7"
  112.     Else: txtResult.Text = txtResult.Text + "7"
  113.     End If
  114. End Sub
  115.  
  116. Private Sub cmd8_Click()
  117.     If txtResult.Text = "Math Error" Then
  118.         txtResult.Text = "Press Clear to Continue"
  119.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  120.         txtResult.Text = "Press Clear to Continue"
  121.     ElseIf txtResult.Text = "0" Then
  122.         txtResult.Text = "8"
  123.     Else: txtResult.Text = txtResult.Text + "8"
  124.     End If
  125. End Sub
  126.  
  127. Private Sub cmd9_Click()
  128.     If txtResult.Text = "Math Error" Then
  129.         txtResult.Text = "Press Clear to Continue"
  130.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  131.         txtResult.Text = "Press Clear to Continue"
  132.     ElseIf txtResult.Text = "0" Then
  133.         txtResult.Text = "9"
  134.     Else: txtResult.Text = txtResult.Text + "9"
  135.     End If
  136. End Sub
  137. \'Operators
  138. Private Sub cmdAdd_Click()
  139.     If txtResult.Text = "Math Error" Then
  140.         txtResult.Text = "Press Clear to Continue"
  141.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  142.         txtResult.Text = "Press Clear to Continue"
  143.     ElseIf operator <> 0 Then
  144.     Else:
  145.         memory = txtResult.Text
  146.         txtResult.Text = ""
  147.         operator = 1
  148.     End If
  149. End Sub
  150.  
  151. Private Sub cmdMinus_Click()
  152.     If txtResult.Text = "Math Error" Then
  153.         txtResult.Text = "Press Clear to Continue"
  154.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  155.         txtResult.Text = "Press Clear to Continue"
  156.     ElseIf operator <> 0 Then
  157.     Else:
  158.     memory = txtResult.Text
  159.     txtResult.Text = ""
  160.     operator = 2
  161.     End If
  162. End Sub
  163.  
  164. Private Sub cmdMulti_Click()
  165.     If txtResult.Text = "Math Error" Then
  166.         txtResult.Text = "Press Clear to Continue"
  167.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  168.         txtResult.Text = "Press Clear to Continue"
  169.     ElseIf operator <> 0 Then
  170.     Else:
  171.     memory = txtResult.Text
  172.     txtResult.Text = ""
  173.     operator = 3
  174.     End If
  175. End Sub
  176.  
  177. Private Sub cmdDivide_Click()
  178.     If txtResult.Text = "Math Error" Then
  179.         txtResult.Text = "Press Clear to Continue"
  180.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  181.         txtResult.Text = "Press Clear to Continue"
  182.     ElseIf operator <> 0 Then
  183.     Else:
  184.     memory = txtResult.Text
  185.     txtResult.Text = ""
  186.     operator = 4
  187.     End If
  188. End Sub
  189.  
  190. Private Sub cmdClear_Click()
  191.     result = 0
  192.     txtResult.Text = 0
  193.     operator = 0
  194.     tempResult = 0
  195. End Sub
  196.  
  197. Private Sub cmdDot_Click()
  198.     If txtResult.Text = "Math Error" Then
  199.         txtResult.Text = "Press Clear to Continue"
  200.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  201.         txtResult.Text = "Press Clear to Continue"
  202.     ElseIf dotCounter = 0 Then
  203.         txtResult.Text = txtResult.Text + "."
  204.         dotCounter = 1
  205.     End If
  206. End Sub
  207.  
  208. Private Sub cmdEnter_Click()
  209.     If txtResult.Text = "Math Error" Then
  210.         txtResult.Text = "Press Clear to Continue"
  211.     ElseIf txtResult.Text = "Press Clear to Continue" Then
  212.         txtResult.Text = "Press Clear to Continue"
  213.     Else
  214.         tempResult = txtResult.Text
  215.         If operator = 0 Then
  216.             txtResult.Text = tempResult
  217.         ElseIf operator = 1 Then
  218.             txtResult.Text = memory + tempResult
  219.         ElseIf operator = 2 Then
  220.             txtResult.Text = memory - tempResult
  221.         ElseIf operator = 3 Then
  222.             txtResult.Text = memory * tempResult
  223.         ElseIf operator = 4 Then
  224.             If tempResult = 0 Then
  225.                 txtResult.Text = "Math Error"
  226.             Else:
  227.                 txtResult.Text = memory / tempResult
  228.             End If
  229.         End If
  230.     End If
  231.     memory = 0
  232.     operator = 0
  233.     dotCounter = 0
  234.    
  235. End Sub
  236.  
  237. \'Exit
  238. Private Sub cmdExit_Click()
  239.  End
  240. End Sub
  241.  
');