Private Sub Command1_Click() Text4 = Text1: Text5 = Text2: Text6 = Text3 If Val(Text4) < Val(Text5) Then a = Text4: Text4 = Text5: Text5 = a If Val(Text4) < Val(Text6) Then a = Text4: Text4 = Text6: Text6 = a If Val(Text5) < Val(Text6) Then a = Text5: Text5 = Text6: Text6 = a End Sub
我的上一个是搞复杂了:Private Sub Command1_Click() Dim x1, x2, x3, tmp x1 = Text1: x2 = Text2: x3 = Text3 If x1 < x2 Then tmp = x1: x1 = x2: x2 = tmp If x1 < x3 Then tmp = x1: x1 = x3: x3 = tmp If x2 < x3 Then tmp = x2: x2 = x3: x3 = tmp Text4 = x1 Text5 = x2 Text6 = x3
For I = 0 To 2
For J = 0 To 2-I
If a(J) > a(J + 1) Then
temp = a(J)
a(J) = a(J + 1)
a(J + 1) = temp
End If
Next J
Next I
这样就可以得到你想要的了
Private Sub Command1_Click()
Dim t1 As String, t2 As String
Dim t3 As String, tb() As String
Dim i As Integer, tmp As String
tmp = "text1 text2 text3"
t1 = IIf(Text1 > Text2, "text1", "text2")
t2 = IIf(Text2 > Text3, "text2", "text3")
t3 = IIf(Me(t1) > Me(t2), t1, t2)
tmp = Replace(Replace(tmp, t3, ""), " ", " ")
tb = Split(Trim(tmp))
Text4 = Me(t3)
Text5 = IIf(Me(tb(0)) > Me(tb(1)), Me(tb(0)), Me(tb(1)))
Text6 = IIf(Me(tb(0)) < Me(tb(1)), Me(tb(0)), Me(tb(1)))
'超过三个数用冒泡排序。
End Sub
Text4 = Text1: Text5 = Text2: Text6 = Text3
If Val(Text4) < Val(Text5) Then a = Text4: Text4 = Text5: Text5 = a
If Val(Text4) < Val(Text6) Then a = Text4: Text4 = Text6: Text6 = a
If Val(Text5) < Val(Text6) Then a = Text5: Text5 = Text6: Text6 = a
End Sub
Dim x1, x2, x3, tmp
x1 = Text1: x2 = Text2: x3 = Text3
If x1 < x2 Then tmp = x1: x1 = x2: x2 = tmp
If x1 < x3 Then tmp = x1: x1 = x3: x3 = tmp
If x2 < x3 Then tmp = x2: x2 = x3: x3 = tmp
Text4 = x1
Text5 = x2
Text6 = x3
End Sub