作者Raisa (绿茶)
看板Visual_Basic
标题[VBA ] 猜数字,数字不在list上???
时间Wed May 20 17:47:08 2009
用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
1F:→ lsst60417:姿势佳也满多高手 建议PO一份去那边 06/17 20:40