Dim i, n, j, k, s, prize(1 To 3) As Integer, a() As Integer
Dim sname(1 To 3) As String
Private Sub Command1_Click()
Randomize
n = Int(3 * Rnd) + 1
If i = 0 Then
a(i) = Int(n) '<<<<---------------------------------------------------就是这个地方 它说我下标越界!!
i = i + 1
Timer1.Enabled = True
ElseIf i > 0 Then
Do While 1 <> 0
If i = 3 Then
MsgBox "没有东西了", 0 + 64, "你真强"
End If
For j = 0 To i - 1
If a(j) = n Then
k = 1
End If
Next j
If k = 1 Then
n = 0 * Rnd + 1
ElseIf k = 0 Then
Exit Do
End If
Loop
a(i) = n
i = i + 1
End If
Text1.SetFocus
Text1.Text = ""
Label1.Caption = sname(n)
If n = 1 Then
Image3.Visible = False
Image2.Visible = False
Image1.Visible = True
ElseIf n = 2 Then
Image1.Visible = False
Image3.Visible = False
Image2.Visible = True
ElseIf n = 3 Then
Image2.Visible = False
Image1.Visible = False
Image3.Visible = True
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
If Text1.Text < prize(n) Then
MsgBox "低了!", 0, "价格"
ElseIf Text1.Text > prize(n) Then
MsgBox "高了!", 0, "价格"
ElseIf Text1.Text = prize(n) Then
MsgBox "恭喜!", 0, "猜对了!"
s = s + prize(n)
Call Command1_Click
End If
End Sub
Private Sub Form_Load()
sname(1) = "电脑"
sname(2) = "手机"
sname(3) = "MP3"
t = 60
i = 0
prize(1) = 8999
prize(2) = 588
prize(3) = 3200
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < Asc(0) Or KeyAscii > Asc(9) Then
Beep
MsgBox "非法字符", 0, "输入"
KeyAscii = 0
End If
End Sub
Private Sub Timer1_Timer()
Static i As Integer
t = t - 1
Label2.Caption = Str(t) & "秒"
If t = 0 Then
MsgBox "时间到", 0 + 64, "哦,BABY~~"
MsgBox "您得了" & s & "元的东东", 0 + 64, "强"
Timer1.Enabled = False
End If
End Sub