对三个数进行按大小排序,下面的代码老提示else没有if,请问错在哪了啊,先不要说代码比较复杂的问题。
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a > b Then
If b > c Then Text4.Text = a & "," & b & "," & c
Else: If a > c Then Text4.Text = a & "," & c & "," & b
Else: Text4.Text = a & "," & b & "," & c
End If
End If
Else
If a > c Then Text4.Text = b & "," & a & "," & c
Else: If b > c Then Text4.Text = b & "," & c & "," & a
Else: Text4.Text = c & "," & b & "," & a
End If
End If
End If
End Sub
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a > b Then
If b > c Then Text4.Text = a & "," & b & "," & c
Else: If a > c Then Text4.Text = a & "," & c & "," & b
Else: Text4.Text = a & "," & b & "," & c
End If
End If
Else
If a > c Then Text4.Text = b & "," & a & "," & c
Else: If b > c Then Text4.Text = b & "," & c & "," & a
Else: Text4.Text = c & "," & b & "," & a
End If
End If
End If
End Sub
这样写,就是完整的一句了,也就是后面的end if 被省略了,导致你后面的else 嵌套出了问题,
请按照标准格式来书写代码
Private Sub Command1_Click()
Dim a As Single, b As Single, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a > b Then
If b > c Then
Text4.Text = a & "," & b & "," & c
Else
If a > c Then
Text4.Text = a & "," & c & "," & b
Else
Text4.Text = a & "," & b & "," & c
End If
End If
Else
If a > c Then
Text4.Text = b & "," & a & "," & c
Else
If b > c Then
Text4.Text = b & "," & c & "," & a
Else
Text4.Text = c & "," & b & "," & a
End If
End If
End If
End Sub