在vb中判断一个三角形属于什么类型啊

PrivateSubCommand1_Click()DimaAsSingle,bAsSingle,cAsSingleIfa=bAndb=cThenLabel2.Capti... Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If

End Sub
我这段代码哪错了啊,为什么老显示一个结果就是正三角形啊,哪位很懂的人给点提示吧。请尽快啊。不胜感激啊
展开
 我来答
ylbshuis
2007-10-15 · TA获得超过854个赞
知道小有建树答主
回答量:1338
采纳率:0%
帮助的人:679万
展开全部
修改下:
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf a = b And b <> c And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = c And c <> b And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf b = c And c <> a And a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf a = b And b <> c Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a = c And c <> b Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf c = b And b <> a Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf a ^ 2 + b ^ 2 = c ^ 2 Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
百度网友12ad932
2007-10-16 · TA获得超过494个赞
知道小有建树答主
回答量:156
采纳率:0%
帮助的人:128万
展开全部
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("a = ", "请输入边长"))
b = Val(InputBox("b = ", "请输入边长"))
c = Val(InputBox("c = ", "请输入边长"))
Select Case True
Case a = 0 Or b = 0 Or c = 0
Label2.Caption = "此三角形是不存在,边长为0"
Case a + b <= c Or b + c <= a Or c + a <= b
Label2.Caption = "此三角形是不存在,无法构成"
Case a = b And b = c
Label2.Caption = "此三角形是正三角形"
Case (a ^ 2 + b ^ 2 = c ^ 2 And a = b And a <> c) Or (b ^ 2 + c ^ 2 = a ^ 2 And b = c And b <> a) Or (c ^ 2 + a ^ 2 = b ^ 2 And c = a And c <> b)
Label2.Caption = "此三角形是等腰直角三角形"
Case (a = b And a <> c) Or (b = c And b <> a) Or (c = a And c <> b)
Label2.Caption = "此三角形是等腰三角形"
Case (a <> b And a <> c And b <> c) And (a ^ 2 + b ^ 2 = c ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Or (c ^ 2 + a ^ 2 = b ^ 2)
Label2.Caption = "此三角形是直角三角形"
Case Else
Label2.Caption = "此三角形是一般三角形"
End Select
End Sub

根据 niuxiaojia45 的,修改了一下,加了两个判断,一个是边长为0,一个是两边长的和小于或等于第三边长。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
澹台姣丽称姣
2020-01-23 · TA获得超过3万个赞
知道大有可为答主
回答量:1.1万
采纳率:30%
帮助的人:570万
展开全部
private
sub
command1_click()
dim
a,
b,
c
as
single
dim
s
as
single,
area
as
single
a
=
val(inputbox("请输入三角形边长a"))
b
=
val(inputbox("请输入三角形边长b"))
c
=
val(inputbox("请输入三角形边长c"))
if
a
+
b
>
c
and
b
+
c
>
a
and
a
+
c
>
b
then
print
"能够成三角形"
s
=
(a
+
b
+
c)
/
2
area
=
sqr(s
*
(s
-
a)
*
(s
-
c)
*
(s
-
b))
print
"面积为:";
area
else
print
"不能够成三角形"
end
if
end
sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
老牛带你看奇闻
2007-10-15 · TA获得超过863个赞
知道小有建树答主
回答量:500
采纳率:0%
帮助的人:776万
展开全部
首先,你的a,b,c的值都没有输入,怎么判断呢!再有就是你的判断条件上有一点乱。我把你的代码稍改了点。你看一下:

Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(InputBox("请输入第一条边"))
b = Val(InputBox("请输入第二条边"))
c = Val(InputBox("请输入第三条边"))
If a < b + c And b < a + c And c < a + b Then
If a = b And b = c Then
Label2.Caption = "此三角形是正三角形"
ElseIf (a = b And a <> c And a ^ 2 + b ^ 2 = c ^ 2) Or (a = c And a <> b And a ^ 2 + b ^ 2 = c ^ 2) Or (b = c And b <> a And a ^ 2 + b ^ 2 = c ^ 2) Then
Label2.Caption = "此三角形是等腰直角三角形"
ElseIf (a = b And a <> c) Or (a = c And a <> b) Or (c = b And c <> a) Then
Label2.Caption = "此三角形是等腰三角形"
ElseIf (a ^ 2 + b ^ 2 = c ^ 2) Or (a ^ 2 + c ^ 2 = b ^ 2) Or (b ^ 2 + c ^ 2 = a ^ 2) Then
Label2.Caption = "此三角形是直角三角形"
Else
Label2.Caption = "此三角形是一般三角形"
End If
Else
MsgBox "输入的三条边不能组成三角形!", vbOKOnly + vbCritical, "提示 "
End If

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式