Public Class Form1
Dim n(6) As Integer
'宣告6個位置分別讓電腦依序抽出六個號碼。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
num()
printnum()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
num()
printnum()
End Sub
Sub num()
For i = 1 To 6
n(i) = Int(Rnd() * 49) + 1
'抽出1~49之中其中一個號碼
For j = 1 To i - 1
If n(j) = n(i) Then n(i) = 0 : i = i - 1
'如果遇到與之前抽過的號碼有衝突則清空該值,重新輸入。
Next
Next
End Sub
Sub printnum()
Label1.Text = n(1)
Label2.Text = n(2)
Label3.Text = n(3)
Label4.Text = n(4)
Label5.Text = n(5)
Label6.Text = n(6)
'最後利用六個Label顯示六個剛剛被抽中的號碼。
End Sub
End Class
0 留言