用vb程序给3个任意数排序

如题所述

下面是两种方法 排

Private Sub Form_Click()
Dim a As Integer, b As Integer, c As Integer
a = 4
b = 2
c = 7
'PaiXu a, b, c
Dim d() As Integer
d = PaiXuArray(a, b, c)
Print a, b, c
Print d(0), d(1), d(2)
End Sub
Function PaiXuArray(ParamArray p()) As Integer()
 Dim b() As Integer
 ReDim b(UBound(p) - LBound(p))
 For i = LBound(p) To UBound(p)
   b(i) = p(i)
 Next
 Dim t As Integer, c As Boolean
 Do
    c = False
    For i = LBound(b) To UBound(b) - 1
      If b(i) > b(i + 1) Then
        t = b(i)
        b(i) = b(i + 1)
        b(i + 1) = t
        If c = False Then c = True
      End If
    Next
 Loop While c
 PaiXuArray = b
End Function
'''按地址传三位数
Sub PaiXu(sum1 As Integer, sum2 As Integer, sum3 As Integer)
Do While PaiSu2(sum1, sum2) Or PaiSu2(sum2, sum3)
Loop
End Sub
Function PaiSu2(ByRef sum1 As Integer, ByRef sum2 As Integer) As Boolean
  If sum1 > sum2 Then
    Dim tem As Integer
    tem = sum1
    sum1 = sum2
    sum2 = tem
    PaiSu2 = True
  End If
End Function

温馨提示:答案为网友推荐,仅供参考
相似回答