Private Sub Text2_Change()
Dim a, b, c As Single
a = CSng(Text1.Text)
b = CSng(Text2.Text)
c = CSng(Text3.Text)
If Option1.Value = True Then
Call opt1
Text5.Text = a / b
ElseIf Option2.Value = True Then
Call opt2
Text5.Text = c / b
End If
End Sub通用窗口函数声明
Sub opt1()
Form1.Text3.Locked = True
Form1.Text3.BackColor = &H80000010
End Sub
Sub opt2()
Form1.Text1.Locked = True
Form1.Text1.BackColor = &H80000010
End Sub
请问这段程序有什么问题,感谢各位
Dim a, b, c As Single
a = CSng(Text1.Text)
b = CSng(Text2.Text)
c = CSng(Text3.Text)
If Option1.Value = True Then
Call opt1
Text5.Text = a / b
ElseIf Option2.Value = True Then
Call opt2
Text5.Text = c / b
End If
End Sub通用窗口函数声明
Sub opt1()
Form1.Text3.Locked = True
Form1.Text3.BackColor = &H80000010
End Sub
Sub opt2()
Form1.Text1.Locked = True
Form1.Text1.BackColor = &H80000010
End Sub
请问这段程序有什么问题,感谢各位
计算的结果是数值
加上Str就好
Text5.Text = Str(a / b)
在 Text2.Text 输入值时出现类型不匹配,怎么回事,我觉得没有问题
先
Dim a, b, c As String
a = Text1.Text
b = Text2.Text
c = Text3.Text
然后
Text5.Text = Str(CSng(a) / CSng(b))
出问题的语句在text2_change中,当然是text2输入时报错。
text5.text=cstr(a/b)
text5.text=cstr(c/d)
a = CSng(Text1.Text)
b = CSng(Text2.Text)
c = CSng(Text3.Text)'当你在更改Text2 的内容时,你要确信 Text1 Text2 Text3内的内容均为数值.
建议作如下更改:
........
........
If IsNumeric(Text1.Text) And IsNumeric(Text2.Text) And IsNumeric(Text3.Text) Then '判断 Text1 Text2 Text3 是否为数值
a = CSng(Text1.Text)
b = CSng(Text2.Text) '增加一句 if B=0 then B=1 'B不能等于0,要不后面会出现错误.
c = CSng(Text3.Text)
Else
a = 0
b = 1 'B不能等于0,要不后面会出现错误.
c = 0
'Text1 Text2 Text3 中有非数值内容
End If
..........
..........