vb 编一个模拟袖珍计算器(textbox3我已经用trim函数去除了前后空格为什么还是不按照输入操作符运算)

2025-05-18 20:18:32
推荐回答(3个)
回答1:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, d As Single
Dim c As Char
a = Val(TextBox1.Text)
b = Val(TextBox3.Text)
c = Trim(TextBox2.Text)
If c = "+" Then
d = a + b
ElseIf c = "-" Then
d = a - b
ElseIf c = "*" Then
d = a * b
ElseIf c = "/" Then

If b = 0 Then
MsgBox("分母为0", "sy3 - 6")
exit sub
End If
d = a / b
End If
TextBox4.Text = d
End Sub

回答2:

"+"c
四个全部加c

回答3:

Dim c As Char 改成 Dim c As String