Simple Calculator

Language
This is a simple calculator written in Visual Basic 6.0.
  1. Public a1 As Double, a2 As Double, result As Double, degri As Double
  2. Public a As String, tem As Integer
  3.  
  4. Dim countertitle, countertitle1 As Integer
  5. Dim title, title1 As String
  6. Dim titledance, titledance1 As String
  7.  
  8. Private Sub cmd0_Click()
  9. txt = txt & 0
  10. End Sub
  11.  
  12. Private Sub cmd1_Click()
  13. txt = txt & 1
  14. End Sub
  15.  
  16. Private Sub cmd2_Click()
  17. txt = txt & 2
  18. End Sub
  19.  
  20. Private Sub cmd3_Click()
  21. txt = txt & 3
  22. End Sub
  23.  
  24. Private Sub cmd4_Click()
  25. txt = txt & 4
  26. End Sub
  27.  
  28. Private Sub cmd5_Click()
  29. txt = txt & 5
  30. End Sub
  31.  
  32. Private Sub cmd6_Click()
  33. txt = txt & 6
  34. End Sub
  35.  
  36. Private Sub cmd7_Click()
  37. txt = txt & 7
  38. End Sub
  39.  
  40. Private Sub cmd8_Click()
  41. txt = txt & 8
  42. End Sub
  43.  
  44. Private Sub cmd9_Click()
  45. txt = txt & 9
  46. End Sub
  47.  
  48. Private Sub cmdback_Click()
  49. If Val(txt.Caption) <> 0 Then
  50. txt.Caption = Left$(txt.Caption, Len(txt.Caption) - 1)
  51. result = Val(txt.Caption)
  52. End If
  53. End Sub
  54.  
  55. Private Sub cmdclear_Click()
  56. txt = ""
  57. cmdpoint.Enabled = True
  58. End Sub
  59.  
  60. Private Sub cmdcot_Click()
  61. degri = txt.Caption
  62. a = "cot"
  63. txt.Caption = ""
  64. a1 = (degri * 22) / 180 * 7
  65. result = 1 / Tan(a1)
  66. If a = "cot" Then
  67. txt.Caption = result
  68. End If
  69. End Sub
  70.  
  71. Private Sub cmddiv_Click()
  72. a1 = txt.Caption
  73. a = "/"
  74. txt.Caption = ""
  75. cmdpoint.Enabled = True
  76. End Sub
  77.  
  78.  
  79. Private Sub cmdmi_Click()
  80. a1 = txt.Caption
  81. a = "-"
  82. txt.Caption = ""
  83. cmdpoint.Enabled = True
  84. End Sub
  85.  
  86. Private Sub cmdmul_Click()
  87. a1 = txt.Caption
  88. a = "*"
  89. txt.Caption = ""
  90. cmdpoint.Enabled = True
  91. End Sub
  92.  
  93. Private Sub cmdnegative_Click()
  94. txt = "-"
  95. End Sub
  96.  
  97. Private Sub cmdplus_Click()
  98. a1 = txt.Caption
  99. a = "+"
  100. txt.Caption = ""
  101. cmdpoint.Enabled = True
  102. End Sub
  103.  
  104. Private Sub cmdpoint_Click()
  105. txt = txt & "."
  106. cmdpoint.Enabled = False
  107. End Sub
  108.  
  109. Private Sub cmdres_Click()
  110. a2 = Val(txt.Caption)
  111. If a = "+" Then result = a1 + a2
  112. If a = "-" Then result = a1 - a2
  113. If a = "*" Then result = a1 * a2
  114. If a = "/" And a2 <> 0 Then result = a1 / a2
  115. txt.Caption = result
  116. If a = "/" And a2 = 0 Then txt.Caption = "Can't divided by zero"
  117. cmdpoint.Enabled = True
  118. End Sub
  119.  
  120. Private Sub cmdsin_Click()
  121. degri = txt.Caption
  122. a = "sin"
  123. txt.Caption = ""
  124. a1 = (degri * 22) / 180 * 7
  125. result = Sin(a1)
  126. If a = "sin" Then
  127. txt.Caption = result
  128. End If
  129. End Sub
  130.  
  131. Private Sub cmdtan_Click()
  132. degri = txt.Caption
  133. a = "tan"
  134. txt.Caption = ""
  135. a1 = (degri * 22) / 180 * 7
  136. result = Tan(a1)
  137. If a = "tan" Then
  138. txt.Caption = result
  139. End If
  140. End Sub
  141. '
  142. 'Private Sub Form_Load()
  143. '    Set Skinner1.Forms = Forms
  144. 'End Sub
  145.  
  146. Private Sub dev_Click()
  147. developer.Show 1
  148. End Sub
  149.  
  150. Private Sub Form_Load()
  151. title = "Calculator"
  152. End Sub
  153.  
  154. Private Sub pro_Click()
  155. system.Show 1
  156.  
  157. End Sub
  158.  
  159. Private Sub Timer1_Timer()
  160. lblcalc.Left = lblcalc.Left - 100 'code to move the newlife tag in the form
  161.  
  162. If lblcalc.Left + lblcalc.Width <= 0 Then
  163. lblcalc.Left = Picture1.Width
  164. End If
  165.  
  166. titledance = Left(title, countertitle)
  167. Me.Caption = titledance
  168. countertitle = countertitle + 1
  169. If countertitle >= Len(title) + 3 Then
  170.     countertitle = 1
  171.     titledance = ""
  172. End If
  173. End Sub

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment