VB求三角形面积,结果老是为零,帮忙看以下代码.Private Sub Text1_Change()a = Val(Text1)End SubPrivate Sub Text2_Change()b = Val(Text2)End SubPrivate Sub Text3_Change()c = Val(Text3)End SubPrivate Sub Command1_Click()Label1 = Sqr(s * (s
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 05:12:04
VB求三角形面积,结果老是为零,帮忙看以下代码.Private Sub Text1_Change()a = Val(Text1)End SubPrivate Sub Text2_Change()b = Val(Text2)End SubPrivate Sub Text3_Change()c = Val(Text3)End SubPrivate Sub Command1_Click()Label1 = Sqr(s * (s
VB求三角形面积,结果老是为零,帮忙看以下代码.
Private Sub Text1_Change()
a = Val(Text1)
End Sub
Private Sub Text2_Change()
b = Val(Text2)
End Sub
Private Sub Text3_Change()
c = Val(Text3)
End Sub
Private Sub Command1_Click()
Label1 = Sqr(s * (s - a) * (s - b) * (s - c))
s = (a + b + c) / 2
End Sub
VB求三角形面积,结果老是为零,帮忙看以下代码.Private Sub Text1_Change()a = Val(Text1)End SubPrivate Sub Text2_Change()b = Val(Text2)End SubPrivate Sub Text3_Change()c = Val(Text3)End SubPrivate Sub Command1_Click()Label1 = Sqr(s * (s
dim a,b,c
Private Sub Text1_Change()
a = Val(Text1)
End Sub
Private Sub Text2_Change()
b = Val(Text2)
End Sub
Private Sub Text3_Change()
c = Val(Text3)
End Sub
Private Sub Command1_Click()
Label1 = Sqr(s * (s - a) * (s - b) * (s - c))
s = (a + b + c) / 2
End Sub
Private Sub Command1_Click()
dim a,b,c,s
a = Val(Text1.text)
b = Val(Text2.text)
c = Val(Text3.text)
s = (a + b + c) / 2
Label1.caption = Sqr(s * (s - a) * (s - b) * (s - c))
End Sub
其他的删去不要。多此一举了。
看来楼主要好好学习VB基本,你TEXT2改变时,没定义全局变量,到CLICK时,只能是0,结果当然只能是0...
前面全不要,只留这个就OK了。有错误也自动跳转了
Private Sub Command1_Click()
On Error Resume Next
If IsNumeric(Text1) = False Then Text1 = "": Text1.S...
全部展开
看来楼主要好好学习VB基本,你TEXT2改变时,没定义全局变量,到CLICK时,只能是0,结果当然只能是0...
前面全不要,只留这个就OK了。有错误也自动跳转了
Private Sub Command1_Click()
On Error Resume Next
If IsNumeric(Text1) = False Then Text1 = "": Text1.SetFocus
If IsNumeric(Text2) = False Then Text2 = "": Text1.SetFocus
If IsNumeric(Text3) = False Then Text3 = "": Text1.SetFocus
Dim s
s = (Val(Text1) + Val(Text2) + Val(Text3)) / 2
Label1.Caption = Sqr(s * (s - a) * (s - b) * (s - c))
End Sub
收起