我的寫法
Private Sub Command1_Click() \'點案件後執行
Dim r(6) As Integer
For i = 0 To 6
r(i) = Int((42 - 1) * Rnd + 1)
Next
Text1.Text = r(0) \'出現在框框理
Text2.Text = r(1)
Text3.Text = r(2)
Text4.Text = r(3)
Text5.Text = r(4)
Text6.Text = r(5)
Text7.Text = r(6)
End Sub
現在我的問題是
1.如何讓他不會重複
2.是否能讓他按照大小排列
3.如果我在設計8~14的框框來輸入投注數字,是否能讓他判斷對幾個數字
2006-05-26 07:26:01 · 1 個解答 · 發問者 ? 3 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click() '點案件後執行 Dim r(6) As Integer For i = 0 To 6 r(i) = Int(42 * Rnd + 1) For j = 0 To i - 1 '不重複 If r(i) = r(j) Then r(i) = Int(42 * Rnd + 1) j = -1 End If Next Next '排序 For i = 0 To 6 - 1 For j = i + 1 To 6 If r(i) > r(j) Then tmp = r(i) r(i) = r(j) r(j) = tmp End If Next Next Text1.Text = r(0) '出現在框框理 Text2.Text = r(1) Text3.Text = r(2) Text4.Text = r(3) Text5.Text = r(4) Text6.Text = r(5) Text7.Text = r(6) Sum = 0 For i = 0 To 6 For j = 8 To 14 If Val(Controls("Text" & j).Text) = r(i) Then Sum = Sum + 1 Next Next MsgBox "您猜中了 " & Sum & " 個!"End Sub
2006-05-26 14:25:15 · answer #1 · answered by 世賢 7 · 0⤊ 0⤋