杀戮都市 小老头:请高手帮我解决VB问题

来源:百度文库 编辑:中科新闻网 时间:2024/04/20 07:40:17
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single 'a 总平米 b 每平米单价 c 总价
a = Text1.Text
b = Text2.Text
c = a * b
Text3.Text = c
End Sub

如何能在不输入a、b 数值的情况下,按确定钮,运行而不会出现错误?

最简单的,在其他语句前加入On Error Resume Next
即:
Private Sub Command1_Click()
On Error Resume Next
...
...
End Sub

Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = a * b
Text3.Text = c
End Sub

if text1.text<>"" then 'text1中不空
a = cdbl(Text1.Text ) 将字符串转化成single数值

注意类型转换

写一个错误处理啊
if (text1.text==null||text2.text==null)
……