vs2008 vb做简单计算器!能算加减乘除就成!

1个回答

  • Dim a As Single

    Dim b As Integer

    Dim c As Single

    Dim d As Single

    Private Sub Command1_Click()

    Text1 = Text1 + "1"

    End Sub

    Private Sub Command10_Click()

    Text1 = Text1 + "0"

    End Sub

    Private Sub Command11_Click()

    Text1 = Text1 + "."

    End Sub

    Private Sub Command12_Click()

    c = Val(Text1)

    If b = 1 Then

    d = a + c

    End If

    If b = 2 Then

    d = a - c

    End If

    If b = 3 Then

    d = a * c

    End If

    If b = 4 Then

    If c = 0 Then

    MsgBox "除数不能为0!", vbOKOnly + vbExclamation, "消息框"

    Else

    d = a / c

    End If

    End If

    If b = 5 Then

    If c = 0 Then

    MsgBox "除数不能为0!", vbOKOnly + vbExclamation, "消息框"

    Else

    d = a c

    End If

    End If

    If b = 6 Then

    d = a ^ c

    End If

    Text1 = Str(d)

    End Sub

    Private Sub Command13_Click()

    a = Val(Text1)

    b = 1

    Text1 = ""

    End Sub

    Private Sub Command14_Click()

    a = Val(Text1)

    b = 2

    Text1 = ""

    End Sub

    Private Sub Command15_Click()

    a = Val(Text1)

    b = 3

    Text1 = ""

    End Sub

    Private Sub Command16_Click()

    a = Val(Text1)

    b = 4

    Text1 = ""

    End Sub

    Private Sub Command17_Click()

    a = Val(Text1)

    b = 5

    Text1 = ""

    End Sub

    Private Sub Command18_Click()

    a = Val(Text1)

    b = 6

    Text1 = ""

    End Sub

    Private Sub Command19_Click()

    Text1 = ""

    End Sub

    Private Sub Command2_Click()

    Text1 = Text1 + "2"

    End Sub

    Private Sub Command20_Click()

    Shell "calc.exe"

    End Sub

    Private Sub Command21_Click()

    Unload Me

    End Sub

    Private Sub Command3_Click()

    Text1 = Text1 + "3"

    End Sub

    Private Sub Command4_Click()

    Text1 = Text1 + "4"

    End Sub

    Private Sub Command5_Click()

    Text1 = Text1 + "5"

    End Sub

    Private Sub Command6_Click()

    Text1 = Text1 + "6"

    End Sub

    Private Sub Command7_Click()

    Text1 = Text1 + "7"

    End Sub

    Private Sub Command8_Click()

    Text1 = Text1 + "8"

    End Sub

    Private Sub Command9_Click()

    Text1 = Text1 + "9"

    End Sub