古詩詞大全網 - 成語經典 - VB:做壹個抽獎機(七個數的)。

VB:做壹個抽獎機(七個數的)。

呵呵,想隨機雙色球?我很早就做過了。妳在窗體添加壹個文本框Text1,添加壹個命令按鈕command1,添加壹個時鐘timer1,代碼如下:Option ExplicitPrivate Sub Command1_Click()

If Timer1.Enabled = False Then

Timer1.Enabled = True

Command1.Caption = "停止"

Else

Timer1.Enabled = False

Command1.Caption = "開始"

End If

End SubPrivate Sub Form_Load()

Command1.Caption = "開始"

Timer1.Enabled = False

Timer1.Interval = 100

End SubPrivate Sub Timer1_Timer()

Dim tmpNum(7) As Integer

Dim i As Integer, j As Integer

Text1 = ""

Randomize '初始化隨機數種子

For i = 0 To 6

ReGet:

tmpNum(i) = Int(Rnd() * 32) + 1

If i > 0 Then

For j = 1 To i

'數字重復則從新得到

If tmpNum(i) = tmpNum(j - 1) Then GoTo ReGet:

Next

End If

DoEvents

Next

'排序

For i = 0 To 6

For j = 0 To 5

If tmpNum(j) > tmpNum(j + 1) Then

tmpNum(7) = tmpNum(j)

tmpNum(j) = tmpNum(j + 1)

tmpNum(j + 1) = tmpNum(7)

End If

DoEvents

Next

DoEvents

Next

For i = 0 To 6

Text1 = Text1 & tmpNum(i) & ","

Next

Text1 = Left(Text1, Len(Text1) - 1)

End Sub