.在窗体上画四个文本框,名称分别为Text1、Text2、Text3和Text4,再画一个名称为Command1的命令按钮。程序
运行后,首先在Text1~Text3中输入三角形三条边的边长,如果这三条边长能构成三角形,单击Command1后,将在Text4中显示出该三角形的面积;否则单击Comma...
运行后,首先在Text1~Text3中输入三角形三条边的边长,如果这三条边长能构成三角形,单击Command1后,将在Text4中显示出该三角形的面积;否则单击Command1后,将显示一个对话框,给出“这三条边长不能构成三角形,请重新输入”的提示信息,同时将Text1~Text3中的内容清空。试编写程序实现以上功能。(怎么做哈)
展开
3个回答
展开全部
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single, S As Single, p As Single
a = CSng(Text1.Text)
b = CSng(Text2.Text)
c = CSng(Text3.Text) '文本框中内容转换为single 类型
If Text1.Text <= 0 Or Text2.Text <= 0 Or Text3.Text <= 0 Then MsgBox "边长要大于零!" '边长要大于零
If a + b > c And b + c > a And a + c > b Then
p = (a + b + c) / 2
S = Sqr(p * (p - a) * (p - b) * (p - c))
Text4.Text = S
Else
MsgBox "这三条边长不能构成三角形,请重新输入"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
Dim a As Single, b As Single, c As Single, S As Single, p As Single
a = CSng(Text1.Text)
b = CSng(Text2.Text)
c = CSng(Text3.Text) '文本框中内容转换为single 类型
If Text1.Text <= 0 Or Text2.Text <= 0 Or Text3.Text <= 0 Then MsgBox "边长要大于零!" '边长要大于零
If a + b > c And b + c > a And a + c > b Then
p = (a + b + c) / 2
S = Sqr(p * (p - a) * (p - b) * (p - c))
Text4.Text = S
Else
MsgBox "这三条边长不能构成三角形,请重新输入"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
展开全部
Option Explicit
Private Sub Command1_Click()
Dim p As Single
If (Val(Text1.Text) + Val(Text2.Text)) > Val(Text3.Text) And _
(Val(Text1.Text) + Val(Text3.Text)) > Val(Text2.Text) And _
(Val(Text3.Text) + Val(Text2.Text)) > Val(Text1.Text) Then
p = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 2
Text4.Text = Int(Sqr(p * (p - Val(Text1.Text)) * (p - Val(Text2.Text)) * _
(p - Val(Text3.Text))))
Else
MsgBox "这三条边不能构成三角形!请重新输入三条边!"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
'p = (a+b+c)/2
's = [ p * (p-a) * (p-b) * (p-c) ] ^ (1 / 2)
's为面积,a,b,c为三角形三条边
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command1_Click()
Dim p As Single
If (Val(Text1.Text) + Val(Text2.Text)) > Val(Text3.Text) And _
(Val(Text1.Text) + Val(Text3.Text)) > Val(Text2.Text) And _
(Val(Text3.Text) + Val(Text2.Text)) > Val(Text1.Text) Then
p = (Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 2
Text4.Text = Int(Sqr(p * (p - Val(Text1.Text)) * (p - Val(Text2.Text)) * _
(p - Val(Text3.Text))))
Else
MsgBox "这三条边不能构成三角形!请重新输入三条边!"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
'p = (a+b+c)/2
's = [ p * (p-a) * (p-b) * (p-c) ] ^ (1 / 2)
's为面积,a,b,c为三角形三条边
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a, b, z, s As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a <= 0 Or b <= 0 Or c <= 0 Then
MsgBox ("边长要大于0,请重新输入")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
Else
p = (a + b + c) / 2
If a + b > c And a - b < c Then
s = Sqr((p) * (p - a) * (p - b) * (p - c))
Text4.Text = s
Else
MsgBox ("这三条边长不能构成三角形,请重新输入")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End If
End Sub
Dim a, b, z, s As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a <= 0 Or b <= 0 Or c <= 0 Then
MsgBox ("边长要大于0,请重新输入")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
Else
p = (a + b + c) / 2
If a + b > c And a - b < c Then
s = Sqr((p) * (p - a) * (p - b) * (p - c))
Text4.Text = s
Else
MsgBox ("这三条边长不能构成三角形,请重新输入")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询