VB中对3个数字进行排列

在窗体上画三个文本框,输入三个数字,单击命令按钮,使这三个数按从小到大的顺序排列,并将结果显示在一个标签上。
在线求呢 各位大哥9命

private sub command_click()
if val(text1.text)>val(text2.text) then
p=text1.text
text1.text=text2.text
text2.text=p
end if

if val(text2.text)>val(text3.text) then
p=text2.text
text2.text=text3.text
text3.text=p
end if

label1.caption="text1.text"&"<"&"text2.text"&"<"&"text3.text"

就是冒泡排序思想,不过着就三个数,用不着太麻烦的思想..我给了答案.如果你想知道确切的冒泡排序就给我留言吧.我再给你说。我要睡了.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-03-25
Private Sub Command1_Click()
Dim num1 As Integer
Dim num2 As Integer
Dim num3 As Integer

num1 = Val(Text1.Text)
num2 = Val(Text2.Text)
num3 = Val(Text3.Text)

Dim temp As Integer

If num1 > num2 Then
temp = num1
num1 = num2
num2 = temp
End If

If num1 > num3 Then
temp = num1
num1 = num3
num3 = temp
End If

If num2 > num3 Then
temp = num2
num2 = num3
num3 = temp
End If

Label4.Caption = "First is : " & num1 & " Second is : " & num2 & " Third is :" & num3

End Sub
第2个回答  2008-03-26
三个数,冒泡要两趟
第一趟最小数放在最前,要两次判断
第二趟次小数放在次前,要一次判断
Private Sub Form_Click()
If Val(Text2.Text) > Val(Text3.Text) Then
p = Text2.Text
Text2.Text = Text3.Text
Text3.Text = p
End If

If Val(Text1.Text) > Val(Text2.Text) Then
p = Text1.Text
Text1.Text = Text2.Text
Text2.Text = p
End If

If Val(Text2.Text) > Val(Text3.Text) Then
p = Text2.Text
Text2.Text = Text3.Text
Text3.Text = p
End If

End Sub
第3个回答  2008-03-25
用冒泡法,这个方法在一般的教材上应该都有。
我的qq是905221006,+我我给你讲。