Dim n(1 To 5) As Integer, max_index As Integer
Private Sub Form_Load()
10 Dim i As Integer, max As Integer
20 max = 0
30 For i = 1 To 5
40 Randomize
50 n(i) = Int(Rnd() * 13) + 1
60 If n(i) > max Then
70 max = n(i)
80 max_index = i - 1
90 End If
100 Next i
End Sub
Private Sub Image1_Click(Index As Integer)
110 Dim j As Integer
120 For j = 0 To 4
130 Image1(j).Picture = LoadPicture(App.Path & \"\\紅心\" & n(j + 1) & \".jpg\")
140 Next j
150 If Index = max_index Then
160 Label2.Caption = \"猜對了!\" & \"第 \" & max_index + 1 & \" 張撲克牌的點數最大\"
170 Else
180 Label2.Caption = \"猜錯了!\" & \"第 \" & max_index + 1 & \" 張撲克牌的點數最大\"
190 End If
End Sub
裡面的牌已經用亂數了但牌還是很固定,第2張和第5張的牌都一樣為什麼會這樣,請幫我解決和要怎麼改??
2006-05-30 09:40:00 · 2 個解答 · 發問者 仔翔 1 in 電腦與網際網路 ➔ 程式設計
Dim n(1 To 5) As Integer, max_index As IntegerPrivate Sub Form_Load()10 Dim i As Integer, max As Integer, B(1 To 13) As Boolean, T As Integer20 Randomize30 For i = 1 To 540 Do50 T = Int(Rnd * 13 + 1)51 Loop Until B(T) = False52 B(T) = True53 n(i) = T60 If n(i) > max Then70 max = n(i)80 max_index = i - 190 End If100 NextEnd SubPrivate Sub Image1_Click(Index As Integer)110 Dim j As Integer120 For j = 0 To 4130 Image1(j).Picture = LoadPicture(App.Path & "\紅心" & n(j + 1) & ".jpg")140 Next150 If Index = max_index Then160 Label2.Caption = "猜對了!" & "第 " & max_index + 1 & " 張撲克牌的點數最大"170 Else180 Label2.Caption = "猜錯了!" & "第 " & max_index + 1 & " 張撲克牌的點數最大"190 End IfEnd Sub
2006-05-31 13:51:59 補充:
利用B陣列作旗標例如如果B(1)=False那就表示1還沒被選中,此時就可跳出回圈,n(i)=1並且將b(1)紀錄為true,否則若B(1)=True就表示1已經被選過了,重選!!
2006-05-30 11:34:18 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋
可不可以加一下中文助解看不懂
2006-05-30 16:49:38 · answer #2 · answered by 仔翔 1 · 0⤊ 0⤋