Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

計算機.vb 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. Public Class 計算機
  2. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False
  4. Me.KeyPreview = True
  5. End Sub
  6. Private Sub Form_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
  7. Select Case e.KeyCode
  8. Case Keys.NumPad1 : Me.ActiveControl = Button1 : Button1.PerformClick() : Me.ActiveControl = Button18
  9. Case Keys.NumPad2 : Me.ActiveControl = Button2 : Button2.PerformClick() : Me.ActiveControl = Button18
  10. Case Keys.NumPad3 : Me.ActiveControl = Button3 : Button3.PerformClick() : Me.ActiveControl = Button18
  11. Case Keys.NumPad4 : Me.ActiveControl = Button4 : Button4.PerformClick() : Me.ActiveControl = Button18
  12. Case Keys.NumPad5 : Me.ActiveControl = Button5 : Button5.PerformClick() : Me.ActiveControl = Button18
  13. Case Keys.NumPad6 : Me.ActiveControl = Button6 : Button6.PerformClick() : Me.ActiveControl = Button18
  14. Case Keys.NumPad7 : Me.ActiveControl = Button7 : Button7.PerformClick() : Me.ActiveControl = Button18
  15. Case Keys.NumPad8 : Me.ActiveControl = Button8 : Button8.PerformClick() : Me.ActiveControl = Button18
  16. Case Keys.NumPad9 : Me.ActiveControl = Button9 : Button9.PerformClick() : Me.ActiveControl = Button18
  17. Case Keys.NumPad0 : Me.ActiveControl = Button10 : Button10.PerformClick() : Me.ActiveControl = Button18
  18. Case Keys.Decimal : Me.ActiveControl = Button12 : Button12.PerformClick() : Me.ActiveControl = Button18
  19. Case Keys.D1 : Me.ActiveControl = Button1 : Button1.PerformClick() : Me.ActiveControl = Button18
  20. Case Keys.D2 : Me.ActiveControl = Button2 : Button2.PerformClick() : Me.ActiveControl = Button18
  21. Case Keys.D3 : Me.ActiveControl = Button3 : Button3.PerformClick() : Me.ActiveControl = Button18
  22. Case Keys.D4 : Me.ActiveControl = Button4 : Button4.PerformClick() : Me.ActiveControl = Button18
  23. Case Keys.D5 : Me.ActiveControl = Button5 : Button5.PerformClick() : Me.ActiveControl = Button18
  24. Case Keys.D6 : Me.ActiveControl = Button6 : Button6.PerformClick() : Me.ActiveControl = Button18
  25. Case Keys.D7 : Me.ActiveControl = Button7 : Button7.PerformClick() : Me.ActiveControl = Button18
  26. Case Keys.D8 : Me.ActiveControl = Button8 : Button8.PerformClick() : Me.ActiveControl = Button18
  27. Case Keys.D9 : Me.ActiveControl = Button9 : Button9.PerformClick() : Me.ActiveControl = Button18
  28. Case Keys.D0 : Me.ActiveControl = Button10 : Button10.PerformClick() : Me.ActiveControl = Button18
  29. Case Keys.OemPeriod : Me.ActiveControl = Button12 : Button12.PerformClick() : Me.ActiveControl = Button18
  30. Case Keys.Delete : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18
  31. Case Keys.Multiply : Me.ActiveControl = Button15 : Button15.PerformClick() : Me.ActiveControl = Button18
  32. Case Keys.Subtract : Me.ActiveControl = Button14 : Button14.PerformClick() : Me.ActiveControl = Button18
  33. Case Keys.OemMinus : Me.ActiveControl = Button14 : Button14.PerformClick() : Me.ActiveControl = Button18
  34. Case Keys.Add : Me.ActiveControl = Button13 : Button13.PerformClick() : Me.ActiveControl = Button18
  35. Case Keys.Oemplus : Me.ActiveControl = Button13 : Button13.PerformClick() : Me.ActiveControl = Button18
  36. Case Keys.Oem2 : Me.ActiveControl = Button16 : Button16.PerformClick() : Me.ActiveControl = Button18
  37. Case Keys.Divide : Me.ActiveControl = Button16 : Button16.PerformClick() : Me.ActiveControl = Button18
  38. Case Keys.Back : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18
  39. Case Keys.Return : Me.ActiveControl = Button11 : Button11.PerformClick() : Me.ActiveControl = Button18
  40. End Select
  41. End Sub
  42. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  43. If TextBox1.Text <> "" Then
  44. TextBox1.Text = TextBox1.Text & 1
  45. Else
  46. TextBox1.Text = 1
  47. End If
  48. End Sub
  49. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  50. If TextBox1.Text <> "" Then
  51. TextBox1.Text = TextBox1.Text & 2
  52. Else
  53. TextBox1.Text = 2
  54. End If
  55. End Sub
  56. Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  57. If TextBox1.Text <> "" Then
  58. TextBox1.Text = TextBox1.Text & 3
  59. Else
  60. TextBox1.Text = 3
  61. End If
  62. End Sub
  63. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  64. If TextBox1.Text <> "" Then
  65. TextBox1.Text = TextBox1.Text & 4
  66. Else
  67. TextBox1.Text = 4
  68. End If
  69. End Sub
  70. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  71. If TextBox1.Text <> "" Then
  72. TextBox1.Text = TextBox1.Text & 5
  73. Else
  74. TextBox1.Text = 5
  75. End If
  76. End Sub
  77. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  78. If TextBox1.Text <> "" Then
  79. TextBox1.Text = TextBox1.Text & 6
  80. Else
  81. TextBox1.Text = 6
  82. End If
  83. End Sub
  84. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  85. If TextBox1.Text <> "" Then
  86. TextBox1.Text = TextBox1.Text & 7
  87. Else
  88. TextBox1.Text = 7
  89. End If
  90. End Sub
  91. Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
  92. If TextBox1.Text <> "" Then
  93. TextBox1.Text = TextBox1.Text & 8
  94. Else
  95. TextBox1.Text = 8
  96. End If
  97. End Sub
  98. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  99. If TextBox1.Text <> "" Then
  100. TextBox1.Text = TextBox1.Text & 9
  101. Else
  102. TextBox1.Text = 9
  103. End If
  104. End Sub
  105. Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  106. If TextBox1.Text <> "" Then
  107. TextBox1.Text = TextBox1.Text & 0
  108. Else
  109. TextBox1.Text = 0
  110. End If
  111. End Sub
  112. Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
  113. If TextBox1.Text <> "" Then
  114. TextBox1.Text = TextBox1.Text & "."
  115. Else
  116. TextBox1.Text = "0."
  117. End If
  118. End Sub
  119. '----------------------------數字鍵盤---------------------------------------------------------------------------------------------------------------
  120. Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
  121. Dim SS As Integer
  122. If TextBox1.Text <> "" Then
  123. TextBox1.Text = Int(Val(TextBox1.Text) / 10)
  124. ElseIf TextBox1.Text = "" And TextBox2.Text <> "" Then
  125. SS = Len(TextBox2.Text)
  126. TextBox2.Text = Strings.Left(TextBox2.Text, SS - 1)
  127. Else
  128. TextBox1.Text = ""
  129. End If
  130. End Sub
  131. Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
  132. Button18.PerformClick()
  133. If TextBox1.Text <> "" And TextBox2.Text = "" Then
  134. TextBox2.Text = TextBox1.Text
  135. TextBox1.Text = ""
  136. End If
  137. If TextBox1.Text <> "" And TextBox2.Text <> "" Then
  138. TextBox2.Text = Val(TextBox2.Text) / Val(TextBox1.Text)
  139. TextBox1.Text = ""
  140. End If
  141. TextBox3.Text = "/"
  142. End Sub
  143. Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
  144. Button18.PerformClick()
  145. If TextBox1.Text <> "" And TextBox2.Text = "" Then
  146. TextBox2.Text = TextBox1.Text
  147. TextBox1.Text = ""
  148. End If
  149. If TextBox1.Text <> "" And TextBox2.Text <> "" Then
  150. TextBox2.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
  151. TextBox1.Text = ""
  152. End If
  153. TextBox3.Text = "X"
  154. End Sub
  155. Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
  156. Button18.PerformClick()
  157. If TextBox1.Text <> "" And TextBox2.Text = "" Then
  158. TextBox2.Text = TextBox1.Text
  159. TextBox1.Text = ""
  160. End If
  161. If TextBox1.Text <> "" And TextBox2.Text <> "" Then
  162. TextBox2.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
  163. TextBox1.Text = ""
  164. End If
  165. TextBox3.Text = "+"
  166. End Sub
  167. Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
  168. Button18.PerformClick()
  169. If TextBox1.Text <> "" And TextBox2.Text = "" Then
  170. TextBox2.Text = TextBox1.Text
  171. TextBox1.Text = ""
  172. End If
  173. If TextBox1.Text <> "" And TextBox2.Text <> "" Then
  174. TextBox2.Text = Val(TextBox2.Text) - Val(TextBox1.Text)
  175. TextBox1.Text = ""
  176. End If
  177. TextBox3.Text = "-"
  178. End Sub
  179. Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
  180. TextBox1.Text = "" : TextBox2.Text = "" : TextBox3.Text = "" : TextBox4.Text = ""
  181. End Sub
  182. Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
  183. TextBox4.Text = TextBox2.Text
  184. If TextBox2.Text = "" Then : Else
  185. If TextBox2.Text - Int(TextBox2.Text) <> 0 Then
  186. TextBox4.Text = Format(Val(TextBox4.Text), "#,##0.0000")
  187. Else
  188. TextBox4.Text = Format(Val(TextBox4.Text), "#,##0")
  189. End If
  190. End If
  191. If Val(TextBox2.Text) > 9.99973000350998E+85 Then
  192. MsgBox("EFFORT错误!结果过大请点击AC重新启动!!!")
  193. End If
  194. End Sub
  195. Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
  196. If TextBox1.Text <> "" And TextBox2.Text <> "" Then
  197. If TextBox3.Text = "X" Then
  198. TextBox2.Text = Val(TextBox1.Text) * Val(TextBox2.Text) : TextBox1.Text = ""
  199. End If
  200. If TextBox3.Text = "/" Then
  201. TextBox2.Text = Val(TextBox2.Text) / Val(TextBox1.Text) : TextBox1.Text = ""
  202. End If
  203. If TextBox3.Text = "+" Then
  204. TextBox2.Text = Val(TextBox1.Text) + Val(TextBox2.Text) : TextBox1.Text = ""
  205. End If
  206. If TextBox3.Text = "-" Then
  207. TextBox2.Text = Val(TextBox2.Text) - Val(TextBox1.Text) : TextBox1.Text = ""
  208. End If
  209. Else
  210. End If
  211. End Sub
  212. End Class