VB编程判断三角形
题目要求判断三角形的形状若能构成三角形判断为等边,等腰,任意编写好后输入数据,我只能判断到等腰,但是等边怎么也无法判断,要么直接显示为等腰,要么为任意。麻烦看下我写的代码...
题目要求判断三角形的形状
若能构成三角形判断为等边,等腰,任意
编写好后输入数据,我只能判断到等腰,但是等边怎么也无法判断,要么直接显示为等腰,要么为任意。麻烦看下我写的代码
Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a + b > c And a + c > b And b + c > a Then
If a = b Or a = c Or b = c Then
Label1.Caption = "等腰三角形"
ElseIf a = b = c Then
Label1.Caption = "等边三角形"
ElseIf Not (a = b Or b = c Or a = c) Then
Label1.Caption = "任意三角形"
End If
Else
Label1.Caption = "不能构成三角形"
End If
End Sub
一楼的方法不行,语句顺序改变都试过,还是显示为等腰 展开
若能构成三角形判断为等边,等腰,任意
编写好后输入数据,我只能判断到等腰,但是等边怎么也无法判断,要么直接显示为等腰,要么为任意。麻烦看下我写的代码
Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a + b > c And a + c > b And b + c > a Then
If a = b Or a = c Or b = c Then
Label1.Caption = "等腰三角形"
ElseIf a = b = c Then
Label1.Caption = "等边三角形"
ElseIf Not (a = b Or b = c Or a = c) Then
Label1.Caption = "任意三角形"
End If
Else
Label1.Caption = "不能构成三角形"
End If
End Sub
一楼的方法不行,语句顺序改变都试过,还是显示为等腰 展开
展开全部
Private Sub Command1_Click()
Dim a As Single
Dim b As Single
Dim c As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a + b + c <> 180 Then
Label1.Caption = "不是三角形"
ElseIf a = b And b = c Then
Label1.Caption = "等边三角形"
ElseIf (a = b And a <> c And c = 90) Or (a = c And a <> b And b = 90) Or (b = c And b <> a And a = 90) Then
Label1.Caption = "等腰直角三角形"
ElseIf (a = b And a <> c And c <> 90) Or (a = c And a <> b And b <> 90) Or (b = c And b <> a And a <> 90) Then
Label1.Caption = "等腰三角形"
ElseIf (a <> b And a <> c And c <> b) And (a = 90 Or b = 90 Or c = 90) Then
Label1.Caption = "直角三角形"
ElseIf a <> b And b <> c And c <> b And a <> 90 And b <> 90 And c <> 90 Then
Label1.Caption = "一般三角形"
End If
End Sub
Private Sub Text1_Change()
On Error Resume Next
If Len(Text1.Text) > 0 And Not (IsNumeric(Text1.Text)) Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
End If
End Sub
Private Sub Text2_Change()
On Error Resume Next
If Len(Text2.Text) > 0 And Not (IsNumeric(Text2.Text)) Then
Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1)
Text2.SelStart = Len(Text2.Text)
End If
End Sub
Private Sub Text3_Change()
On Error Resume Next
If Len(Text3.Text) > 0 And Not (IsNumeric(Text3.Text)) Then
Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1)
Text3.SelStart = Len(Text3.Text)
End If
End Sub
Dim a As Single
Dim b As Single
Dim c As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a + b + c <> 180 Then
Label1.Caption = "不是三角形"
ElseIf a = b And b = c Then
Label1.Caption = "等边三角形"
ElseIf (a = b And a <> c And c = 90) Or (a = c And a <> b And b = 90) Or (b = c And b <> a And a = 90) Then
Label1.Caption = "等腰直角三角形"
ElseIf (a = b And a <> c And c <> 90) Or (a = c And a <> b And b <> 90) Or (b = c And b <> a And a <> 90) Then
Label1.Caption = "等腰三角形"
ElseIf (a <> b And a <> c And c <> b) And (a = 90 Or b = 90 Or c = 90) Then
Label1.Caption = "直角三角形"
ElseIf a <> b And b <> c And c <> b And a <> 90 And b <> 90 And c <> 90 Then
Label1.Caption = "一般三角形"
End If
End Sub
Private Sub Text1_Change()
On Error Resume Next
If Len(Text1.Text) > 0 And Not (IsNumeric(Text1.Text)) Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
Text1.SelStart = Len(Text1.Text)
End If
End Sub
Private Sub Text2_Change()
On Error Resume Next
If Len(Text2.Text) > 0 And Not (IsNumeric(Text2.Text)) Then
Text2.Text = Left(Text2.Text, Len(Text2.Text) - 1)
Text2.SelStart = Len(Text2.Text)
End If
End Sub
Private Sub Text3_Change()
On Error Resume Next
If Len(Text3.Text) > 0 And Not (IsNumeric(Text3.Text)) Then
Text3.Text = Left(Text3.Text, Len(Text3.Text) - 1)
Text3.SelStart = Len(Text3.Text)
End If
End Sub
展开全部
条件改成这个
If a + b > c And a + c > b And b + c > a Then
If a = b Or a = c Or b = c Then
Label1.Caption = "等腰三角形"
ElseIf a = b and b = c and c=a Then
Label1.Caption = "等边三角形"
ElseIf Not (a = b Or b = c Or a = c) Then
Label1.Caption = "任意三角形"
End If
Else
Label1.Caption = "不能构成三角形"
End If
If a + b > c And a + c > b And b + c > a Then
If a = b Or a = c Or b = c Then
Label1.Caption = "等腰三角形"
ElseIf a = b and b = c and c=a Then
Label1.Caption = "等边三角形"
ElseIf Not (a = b Or b = c Or a = c) Then
Label1.Caption = "任意三角形"
End If
Else
Label1.Caption = "不能构成三角形"
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询