发新话题
打印

[基础] VB里面简单计算机代码有什么错误

VB里面简单计算机代码有什么错误

Private Sub Command1_Click()
opt = "+"
End Sub

Private Sub Command2_Click()
opt = "-"
End Sub

Private Sub Command3_Click()
opt = "*"
End Sub

Private Sub Command4_Click()
opt = "/"
End Sub

Private Sub Command5_Click()
Dim a, b, result As Double
a = Text1.Text
b = Text2.Text
Select Case opt
Case "+"
result = Val(a) + Val(b)
Case "-"
result = Val(a) - Val(b)
Case "*"
result = Val(a) * Val(b)
Case "/"
result = Val(a) / Val(b)
End Select
Text3.Text = result
End Sub

Private Sub Text1_Change()

End Sub

Private Sub Text2_Change()

End Sub

Private Sub Text3_Change()

End Sub

为什么第三个text里面的值总是0,向高手请教

TOP

opt需在定义成公共变量
换个头像,看见广告就眼红,直接封ID。

TOP

谢谢,我是新手,对不起提这么弱智的问题

TOP

换个头像,看见广告就眼红,直接封ID。

TOP

发新话题