关于VB的问题,知道的答

来源:百度知道 编辑:UC知道 时间:2024/05/25 09:22:45
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
Label1.Caption =""
a = Val(Text1.Text)
b = Val(Text2.Text)
c = a + b
Label1.Caption ="答案为" c

End Sub
运行为什么会出错。

Label1.Caption ="答案为" & c

Label1.Caption ="答案为" & c

中间要有连接符,而且连接符 "&" 的左右要有空格

数据类型不统一,caption后面应该是字符串.而C又为数值型.所有要把C转换一下
把Label1.Caption ="答案为" c 改为
Label1.Caption = "答案为" & Str$(c)