2008年12月9日 星期二

VB數字排序程式碼

參考看看.. 有更好的方法,再請同學指教!!
=====================================
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, i As Integer
If IsNumeric(TextBox1.Text) = True And IsNumeric(TextBox2.Text) = True And IsNumeric(TextBox3.Text) = True And IsNumeric(TextBox4.Text) = True Then
If textbox1.text = textbox2.text Or textbox1.text = textbox3.text Or textbox1.text = textbox4.text Or textbox2.text = textbox3.text Or textbox2.text = textbox4.text Or textbox3.text = textbox4.text Then
MsgBox("數字不得重覆!!")
Else
For i = 1 To 6
If textbox1.text < textbox2.text Then
If textbox2.text < textbox3.text Then
If textbox3.text < textbox4.text Then
Exit For
Else
x = textbox4.text
textbox4.text = textbox3.text
textbox3.text = x
End If
Else
x = textbox3.text
textbox3.text = textbox2.text
textbox2.text = x
End If
Else
x = textbox2.text
textbox2.text = textbox1.text
textbox1.text = x
End If
Next
MsgBox(textbox1.text & "," & textbox2.text & "," & textbox3.text & "," & textbox4.text)
End If
Else
MsgBox("欄位不得空白或特殊符號!!請重新輸入!")
End If
End Sub
End Class
=====================================
我有修改了一下,請同學幫忙看是否有問題..
如果沒問題的話,做『由大到小』就把 < 換成 > 應該就可以了!!
對調一下