Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Randomize() '亂數初始化
        Dim draw(9) As Integer
        Dim stdnum As Integer
        Dim ans As Integer
        stdnum = TextBox1.Text '輸入亂數範圍
        For i = 0 To 9
            While draw(i) = 0
                ans = CInt(Int(Rnd() * stdnum) + 1) '產生亂數
                If Array.IndexOf(draw, ans) = -1 Then '檢查亂數是否有重複
                    draw(i) = ans
                End If
            End While
        Next

        TextBox2.Text = draw(0)
        TextBox3.Text = draw(1)
        TextBox4.Text = draw(2)
        TextBox5.Text = draw(3)
        TextBox6.Text = draw(4)
        TextBox7.Text = draw(5)
        TextBox8.Text = draw(6)
        TextBox9.Text = draw(7)
        TextBox10.Text = draw(8)
        TextBox11.Text = draw(9)

    End Sub

End Class


創作者介紹
創作者 wmhuang 的頭像
wmhuang

喵姑娘的備忘錄

wmhuang 發表在 痞客邦 留言(0) 人氣()