求计算器vb做法,谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/26 06:13:50
1. The calculator should accept up to 16 digits in the display.
2. There should be only one display.
3. There will be buttons for the numbers 0 to 9, plus the decimal
4. There will be buttons for the functions add, subtract, multiply and divide, plus a final total button labeled with the = sign.
5. There will be two clear buttons:
a) Clear Entry - clears the value currently in the display
b) Clear - clears all calculations, resetting to zero.
6. The calculator will work by inputting a number, then an function key, then another number, then pressing the = button.
7. The entire calculator must be one complete form, not a portion of a form, and not larger than the form.
8. If the user enters another function instead of the = button, the calculator will display ERROR on the display.

我编写的,不过已经通过测试

Public Class frmcomputer
Dim strA As String = ""
Dim strB As String = " "
Dim c As String = "+"
Dim n As String = " "

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtexpr.TextChanged
strB = txtexpr.Text
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
strB = Button1.Text
txtexpr.Text = txtexpr.Text + strB
strB = txtexpr.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
strB = Button2.Text
txtexpr.Text = txtexpr.Text + strB

strB = txtexpr.Text
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As