对三个数进行按大小排序,下面的代码老提示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

解决方案 »

  1.   

    If b >  c Then Text4.Text = a & "," & b & "," & c 
    这样写,就是完整的一句了,也就是后面的end if 被省略了,导致你后面的else 嵌套出了问题,
    请按照标准格式来书写代码
      

  2.   

    明白了,看来vb中对格式要求好严格啊,谢了
    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