Public Class Form1
Dim defPic(5) As PictureBox'真按:此應是4就夠,可能為程式引用方便
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblRnd.Text = "排序前:"
lblSort.Text = "排序後:"
defPic(1) = pic1 : defPic(2) = pic2 : defPic(3) = pic3
defPic(4) = pic4 : defPic(5) = pic5
For i = 0 To 4
defPic(i + 1).Image = New Bitmap("Pokerbk.jpg")
Next
End Sub
' GetRnd函式可用來取得n~m之間的num個不重複的亂數,並傳給所設定的陣列
Sub GetRnd(ByRef vArray() As Integer, ByVal min As Integer, ByVal max As _
Integer, ByVal num As Integer)
Dim i, j, max_dim, rem_num, choice As Integer
max_dim = max - min
Dim t(max_dim) As Integer
For i = 0 To max_dim
t(i) = min + i
Next
rem_num = max_dim
Randomize()
For i = 0 To num - 1
choice = Fix(rem_num) * Rnd()
vArray(i) = t(choice)
For j = choice To rem_num - 1
t(j) = t(j + 1)
Next
rem_num -= 1'真按:不重複
Next
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim pk(4) As Integer
GetRnd(pk, 1, 13, 5)
lblRnd.Text = "排序前:"
Dim i As Integer
For i = 0 To 4
lblRnd.Text &= pk(i) & ", "
Next
Array.Sort(pk)
lblSort.Text = "排序後:"
For i = 0 To 4
lblSort.Text &= pk(i) & ", "
defPic(i + 1).Image = New Bitmap("Poker" & pk(i) & ".jpg")
Next
End Sub
End Class