比较三个文本框中的数值大小??
text1.text = x
text2.text = y
text3.text = z
比较x,y,z大小,按大、中、小的顺序,分别输入到text4.text,text5.text,text6.text中。
请写出代码来,谢谢!
[解决办法]
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
[解决办法]
Private Sub Command1_Click()Text4 = Text1: Text5 = Text2: Text6 = Text3If Val(Text4) < Val(Text5) Then a = Text4: Text4 = Text5: Text5 = aIf Val(Text4) < Val(Text6) Then a = Text4: Text4 = Text6: Text6 = aIf Val(Text5) < Val(Text6) Then a = Text5: Text5 = Text6: Text6 = aEnd 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 End Sub