VB程序设计:判断任意的三条边长能否构成三角形并计算其面积
应用InputBox()函数和MsgBox语句与函数的使用方法,单击判断按钮调用InputBox函数,分别将任意的三个数字输入,输入完毕后将三个数字分别显示在三个text...
应用InputBox()函数和MsgBox语句与函数的使用方法,单击判断按钮调用InputBox函数,分别将任意的三个数字输入,输入完毕后将三个数字分别显示在三个text控件中,程序自动判断三个数字能否构成三角形,如果能则在Label4显示其三条边长的数据,在Label5中显示其构成的面积;如果不能构成三角形则利用Msgbox提示“不能构成三角形”。如果输入有负数时,也利用Msgbox提示“您所输入的数据无效”
展开
展开全部
单击Command1即可。代码如下。
==============================
Dim a As Single, b As Single, c As Single, p As Single, S As Single
Private Sub Command1_Click()
On Error GoTo e
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
p = (a + b + c) / 2
If a < p And b < p And c < p Then
S = Sqr(p * (p - a) * (p - b) * (p - c))
MsgBox S
Else
GoTo e
End If
Exit Sub
e:
MsgBox "不能构成三角形"
End Sub
==============================
Dim a As Single, b As Single, c As Single, p As Single, S As Single
Private Sub Command1_Click()
On Error GoTo e
a = InputBox("a=")
b = InputBox("b=")
c = InputBox("c=")
p = (a + b + c) / 2
If a < p And b < p And c < p Then
S = Sqr(p * (p - a) * (p - b) * (p - c))
MsgBox S
Else
GoTo e
End If
Exit Sub
e:
MsgBox "不能构成三角形"
End Sub
展开全部
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, p As Single, S As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
Label4.Caption = Val(Text1.Text) & vbCrLf & Val(Text2.Text) & vbCrLf & Val(Text3.Text)
If a + b > c And a + c > b And b + c > a Then
p = (a + b + c) / 2
Label5.Caption = Sqr(p * (p - a) * (p - b) * (p - c))
Else
MsgBox "不能构成三角形"
End If
End Sub
Private Sub Form_Load()
Text1.Text = InputBox("输入三角形边长a")
Text2.Text = InputBox("输入三角形边长b")
Text3.Text = InputBox("输入三角形边长c")
End Sub
Private Sub Command2_Click()
unload me
End Sub
Dim a As Single, b As Single, c As Single, p As Single, S As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
Label4.Caption = Val(Text1.Text) & vbCrLf & Val(Text2.Text) & vbCrLf & Val(Text3.Text)
If a + b > c And a + c > b And b + c > a Then
p = (a + b + c) / 2
Label5.Caption = Sqr(p * (p - a) * (p - b) * (p - c))
Else
MsgBox "不能构成三角形"
End If
End Sub
Private Sub Form_Load()
Text1.Text = InputBox("输入三角形边长a")
Text2.Text = InputBox("输入三角形边长b")
Text3.Text = InputBox("输入三角形边长c")
End Sub
Private Sub Command2_Click()
unload me
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.第二张图看不清
2.你两个图程序不一致
你的三个框名字必须为text1,text2,text3
而你的第一张图的tetx3应该是拼错了
2.你两个图程序不一致
你的三个框名字必须为text1,text2,text3
而你的第一张图的tetx3应该是拼错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询