注册 登录
编程论坛 VB6论坛

各位老师帮我看看为什么?

cyl5420 发布于 2016-06-14 07:08, 1492 次点击
text2输入小于1的数就出错


Private Sub Label1_Click() '''''''''谐振频率
If Val(Text2.Text) And Val(Text3.Text) <> 0 Then
Text7.Text = 1 / (6.28318530714 * Sqr(Val(Text3.Text) / 1000 * Val(Text2.Text) / 1000000))
Else: Text7.Text = "请输入正确的数值"
End If
If Val(Text4.Text) And Val(Text3.Text) <> 0 Then
Text7.Text = 1 / (0.0394784176 * Val(Text4.Text) * Val(Text4.Text) * Val(Text3.Text))
Else: Text7.Text = "请输入正确的数值"
End If
If Val(Text4.Text) And Val(Text2.Text) <> 0 Then
Text7.Text = 1 / (0.0394784176 * Val(Text4.Text) * Val(Text4.Text) * Val(Text2.Text))
Else: Text7.Text = "请输入正确的数值"
End If
5 回复
#2
风吹过b2016-06-14 08:18
If Val(Text2.Text) And Val(Text3.Text) <> 0 Then
text2 内容转数值 与 text3 的内容转数值。然后用整数部分执行 AND 位操作,最后结果是否等于0 。
请问你的问题出在那一部分?
#3
wds12016-06-14 08:39
我执行没报错,你输入的都是什么数。
只有本站会员才能查看附件,请 登录

输入负数报错,因为负数不能开平方。
#4
xiangyue05102016-06-14 08:43
从代码来看没有什么问题,有可能是风版说的这样的问题
另外,提问的时候说清楚问题是什么。毕竟你提供的只是一个片段,别人复现你的错误有一定难度。
你说的出错可以是调试错误,那么出错位置、错误信息。 也可能是计算结果出错。
#5
chen35232016-06-14 08:54

If Val(Text4.Text) And Val(Text2.Text) <> 0 Then 'Text4没有任何判断作用
Text7.Text = 1 / (0.0394784176 * Val(Text4.Text) * Val(Text4.Text) * Val(Text2.Text))
Else: Text7.Text = "请输入正确的数值"   '程序运行后,前面两个判断都没用,只显示这结果,因为所有结果都在Text7显示。
End If
#6
ZHRXJR2016-06-14 13:19
If Val(Text2.Text) And Val(Text3.Text) <> 0 Then   这个语句应该有问题吧?
应该是 If Val(Text2.Text) <> 0  And Val(Text3.Text) <> 0 Then
另外 Text7.Text = 1 / (6.28318530714 * Sqr(Val(Text3.Text) / 1000 * Val(Text2.Text) / 1000000))
如果Val(Text2.Text) < 0,那么 Val(Text3.Text) / 1000 * Val(Text2.Text) / 1000000这部分好像是负值,还能Sqr吗
应该是Text7.Text = 1 / (6.28318530714 * Sqr(Abs(Val(Text3.Text)) / 1000 * Abs(Val(Text2.Text)) / 1000000))
在Sqr内的变量应该取绝对值。

[此贴子已经被作者于2016-6-14 13:28编辑过]

1