2008年12月24日 星期三

排名排序Sample


Public Class Form1
Dim str1 = ""
Dim i, j
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'原始資料
Dim a() = {92, 83, 95, 71, 94}
Dim r(5)

'排序前資料輸出
For i = 0 To 4
str1 = str1 & a(i) & " "
Next
MsgBox(str1)

'排名排序
For j = 0 To 4
r(j) = 1
For i = 0 To 4
If a(j) < a(i) Then r(j) = r(j) + 1
Next
Next

'排序後資料輸出
str1 = ""
For i = 0 To 4
str1 = str1 & a(i) & " " & "名次:" & r(i) & vbNewLine
Next
MsgBox(str1)
End Sub
End Class

沒有留言:

張貼留言