[VBA ] 猜數字,數字不在list上???

看板Visual_Basic作者 (綠茶)時間16年前 (2009/05/20 17:47), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
用excel寫的 照書打,一直出錯 目前卡在不會在listbox出現打過的數字 可以請問有人知道該怎麼改才好嗎? 謝謝 以下是全部 黃色的地方是比較有問題的 Dim a(3) As Integer Dim gst(3) As Integer Dim tTimes As Integer Private Sub CommandButton1_Click() Randomize For i = 0 To 3 a(i) = -1 gst(i) = -1 Next i i = 0 While i < 4 a(i) = Int(10 * Rnd) flag = False For j = 0 To i - 1 If a(i) = a(j) Then flag = True Exit For End If Next j If flag = False Then i = i + 1 End If Wend ListBox1.Clear tTimes = 0 TextBox1.Text = "" End Sub Private Sub CommandButton2_Click() Dim aa, bb As Integer aa = 0 bb = 0 If Len(TextBox1.Text) <> 4 Then MsgBox "必須輸入四位不重覆的數字!", vbOKOnly + vbInformation, "" TextBox1.Text = "" Exit Sub End If For i = 1 To 4 gst(i - 1) = Val(Mid(TextBox1.Text, i, 1)) Next i For i = 1 To 3 For j = 0 To i - 1 If gst(i) = gst(j) Then MsgBox "數字有重覆!", vbOKOnly + vbInformation, "猜數字遊戲" TextBox1.Text = "" Exit Sub End If Next j Next i For x = 0 To 3 If a(x) = gst(x) Then aa = aa + 1 Else For y = 0 To 3 If y <> x And a(x) = gst(y) Then bb = bb + 1 Next y End If Next x tTimes = tTimes + 1 ListBox1.AddItem TextBox1.Text & " " & aa & "A" & bb & "B 第" & tTimes & TextBox1.Text = "" If aa = 4 Then Select Case tTimes Case 1 To 10: ss = "你好厲害,高手!" Case 11 To 15: ss = "還不錯啦!" Case 16 To 20: ss = "再加點油囉!" Case Else: ss = "有待努力""" End Select MsgBox ss, vbOKOnly + vbInformation, " 猜數字遊戲" Call CommandButton1_Click Else MsgBox aa & "A" & bb & "B", vbOKOnly + vbInformation, " 猜數字遊戲" End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If Not (KeyAscii >= 48 And KeyAscii <= 57) And KeyAscii <> 8 Then KeyAscii = 0 End Sub Private Sub UserForm_load() Call CommandButton1_Click End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.170.70.123

06/17 20:40, , 1F
姿勢佳也滿多高手 建議PO一份去那邊
06/17 20:40, 1F
文章代碼(AID): #1A4z6Tzj (Visual_Basic)