两个关于VB的问题,希望朋友们来回答啊~~

来源:百度知道 编辑:UC知道 时间:2024/06/06 17:53:55
第一个:关于判断三角形的
Private Sub Command1_Click()
Dim a, b, c As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
If (a <= 0 Or b <= 0 Or c <= 0) And (a + b < c Or b + c < a Or a + c < b) Then
Label1.Caption = "这不是一个三角形"
ElseIf a = b And a = c Then
Label1.Caption = "这是一个等边三角形"
ElseIf (a = b And a <> c) Or (a = c And b <> c) Or (b = c And a <> c) Then
Label1.Caption = "这是一个等腰三角形"
ElseIf a <> b And b <> c And a <> c Then
Label1.Caption = "这是一个任意三角形"
End If
End Sub
为什么我输入55,55,1也是正确的呢?
第二个:关于比较三个数字大小的
Private Sub Command1_Click()
Dim a, b, c, d As Single
a = Text1.Text
b = Text2.Text
c = Text3.Text
If a > b Then
d = a
a = b
b = d
Else
a = a
b = b
End If
If a > c Then
d = a
a = c

1、55,55,1可以组成三角形呀。
2、代码没错,错在变量声明上。这么改一下就行。
Dim a As Single, b As Single, c As Single, d As Single

前一种是声明成默认变体型,后一种显示声明成integer型,当然不同了。
至于第一问,错误跟第二问一样,需要改一下声明:
Dim a As Integer , b As Integer , c As Integer