- 最後登錄
- 2024-11-16
- 在線時間
- 7253 小時
- 註冊時間
- 2010-5-4
- 閱讀權限
- 95
- 精華
- 0
- UID
- 7964333
- 帖子
- 155
- 積分
- 1282 點
- 潛水值
- 47975 米
| 回覆中加入附件並不會使你增加積分,請使用主題方式發佈附件。 本帖最後由 tryit244178 於 2017-5-10 04:31 PM 編輯
呃…編輯一下整個程式碼都噴掉了…
算了…宣告個陣列紀錄已經取出過的數字就行了
來補程式碼,先建立一個物件類別模組
- '物件類別模組 Class1
- Private bingoNumberLog(1 To 25) As Boolean
- Public Sub Reset()
- Dim i As Integer
-
- For i = 1 To 25
- bingoNumberLog(i) = False
- Next i
- End Sub
- Public Function GetNumber() As Integer
- Do
- GetNumber = GetRndNumber(25)
- Loop Until Not IsRepeat(GetNumber)
-
- bingoNumberLog(GetNumber) = True
- End Function
- Private Function GetRndNumber(ByVal value As Integer) As Integer
- Randomize
- GetRndNumber = Int(Rnd() * value) + 1
- End Function
- Private Function IsRepeat(ByVal value As Integer) As Boolean
- IsRepeat = False
- If bingoNumberLog(value) = True Then IsRepeat = True
- End Function
複製代碼
範例是這個。參考看看吧
- 'Demo
- Private Sub CommandButton1_Click()
- Dim i As Integer
- Dim bingo As New Class1
-
- bingo.Reset
- TextBox1.Text = ""
-
- For i = 1 To 25
- TextBox1.Text = TextBox1.Text & bingo.GetNumber & " , "
- Next i
- End Sub
複製代碼
... |
|