English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

就是我現在可以做到這種地步...但是數字會重覆要如何不要讓數字不要重覆呢!!
以下是我的程式碼

Private Sub Command1_Click()
Timer1.Enabled = False
End Sub

Private Sub Command2_Click()
Timer1.Enabled = True
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Timer1_Timer()
Randomize
Label1.Caption = Int(Rnd() * 42) + 1
Label2.Caption = Int(Rnd() * 42) + 1
Label3.Caption = Int(Rnd() * 42) + 1
Label4.Caption = Int(Rnd() * 42) + 1
Label5.Caption = Int(Rnd() * 42) + 1
Label6.Caption = Int(Rnd() * 42) + 1
Label7.Caption = Int(Rnd() * 42) + 1
End Sub

要如何改呢!!!

2006-07-12 11:54:24 · 2 個解答 · 發問者 ├♀麻 糬♀┤ 1 in 電腦與網際網路 程式設計

2 個解答

'類似的問題已經有很多人回答過了,可利用搜尋找找看Private Sub Timer1_Timer()    Dim B(1 To 42) As Boolean, I As Integer, N As Integer    Randomize        For I = 1 To 7        Do          N = Int(Rnd() * 42) + 1        Loop Until B(N) = False        B(N) = True        Controls("Label" & I).Caption = N    NextEnd Sub

2006-07-12 14:13:22 · answer #1 · answered by W.J.S. 7 · 0 0

'我的方法是使用二維陣列
'其中需要按鈕3個cmd1~3
'Label物件陣列Lbl1(0~5)就是5個Label
'Timer 1個 T1

Dim loto(48, 1) As Integer
Private Sub Cmd1_Click()
If Cmd1.Caption = "開下一號" Then
Cmd1.Caption = "停止"
T1.Enabled = True
Cmd2.Enabled = False
Else
Cmd1.Caption = "開下一號"
T1.Enabled = False
Cmd2.Enabled = True
End If
End Sub

Private Sub Cmd2_Click()
Dim f As Integer
For f = 0 To 5
Lbl1(f).Caption = ""
Next f
End Sub

Private Sub Cmd3_Click()
End
End Sub

Private Sub Form_Load()
Dim a As Integer
T1.Enabled = False
For a = 0 To 48
loto(a, 0) = a + 1
Next a
End Sub

Private Sub T1_Timer()
Dim b, c, d, tem, temp, e As Integer
Randomize
For b = 0 To 48
loto(b, 1) = Int(Rnd * 777 + 1)
Next b
For c = 0 To 48
For d = 0 To 48
If loto(c, 1) < loto(d, 1) Then
tem = loto(c, 1)
loto(c, 1) = loto(d, 1)
loto(d, 1) = tem
temp = loto(c, 0)
loto(c, 0) = loto(d, 0)
loto(d, 0) = temp
End If
Next d
Next c
For e = 0 To 5
Lbl1(e).Caption = loto(e, 0)
Next e
End Sub

2006-07-13 00:30:29 補充:
這是我以前寫的程式 內容是大樂透如果要改成小樂透只需將裡面所有的48改成41就可以了還有我裡面的物件都是自己命名的例如: Command1 我改成 Cmd1 Timer1 --------> T1諸如此類自行VB物件的 Name 屬性欄修改即可

2006-07-12 19:55:45 · answer #2 · answered by 1 · 0 0

fedest.com, questions and answers