拜托各位编程高手了,我想编一个猜数大师的程序,他怎么说缺少变量?麻烦帮我修改一下,谢谢! 50
OptionExplicitOptionBase1Dimnumber(10)AsIntegerDimXXXX(4)AsIntegerDimYYYY(4)AsInteger...
Option Explicit
Option Base 1
Dim number(10) As Integer
Dim XXXX(4) As Integer
Dim YYYY(4) As Integer
Dim X As Integer
Dim Y As Integer
Dim rndnum As Integer
Private Sub cmdStart_Click()
cmdOK.Enabled = True
lblDone.Caption = "新数字已生成"
lblanswer.Caption = ""
lblTimes.Caption = ""
Call Cls
For X = LBound(number) To UBound(number)
number(X) = X - 1
Next
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Call Randomize
rndnum = 1 + Int(Rnd() * 10)
XXXX(1) = number(rndnum)
number(rndnum) = number(10)
number(10) = XXXX(1)
rndnum = 1 + Int(Rnd() * 9)
XXXX(2) = number(rndnum)
number(rndnum) = number(9)
number(9) = XXXX(2)
rndnum = 1 + Int(Rnd() * 8)
XXXX(3) = number(rndnum)
number(rndnum) = number(8)
number(8) = XXXX(3)
rndnum = 1 + Int(Rnd() * 7)
XXXX(4) = number(rndnum)
number(rndnum) = number(7)
number(7) = XXXX(4)
End Sub
Private Sub cmdOK_Click()
txtInput.SetFocus
Static times As Integer
Static A As Integer
Static B As Integer
A = 0
B = 0
ldlDone.Caption = ""
For Y = 1 To 4
YYYY(Y) = Val(Mid$(txtInput.Text, Y, 1))
Next Y
If YYYY(1) <> YYYY(2) Then
If YYYY(3) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(4) <> YYYY(3) Then
If YYYY(4) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(2) And YYYY(4) <> YYYY(3) Then
For X = LBound(XXXX) To UBound(XXXX)
For Y = LBound(YYYY) To UBound(YYYY)
If XXXX(X) = YYYY(Y) Then
If XXXX(X) = YYYY(X) Then
A = A + 1
Else
B = B + 1
End If
End If
Next Y
Next X
Print YYYY(1) & YYYY(2) & YYYY(3) & YYYY(4), A&; "A" & B & "B"
times = times + 1
If times + 10 Then
cmdOK.Enabled = False
lblTimes.Caption = "你没有机会了,还是看看答案吧!"
times 0
Else
lblTimes.Caption = "你还有" & 10 - times & "次机会"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
txtInput.Text = ""
End Sub
Private Sub cmdanswer_Click()
lblanswer.Caption = XXXX(1) & XXXX(2) & XXXX(3) & XXXX(4)
End Sub 展开
Option Base 1
Dim number(10) As Integer
Dim XXXX(4) As Integer
Dim YYYY(4) As Integer
Dim X As Integer
Dim Y As Integer
Dim rndnum As Integer
Private Sub cmdStart_Click()
cmdOK.Enabled = True
lblDone.Caption = "新数字已生成"
lblanswer.Caption = ""
lblTimes.Caption = ""
Call Cls
For X = LBound(number) To UBound(number)
number(X) = X - 1
Next
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Call Randomize
rndnum = 1 + Int(Rnd() * 10)
XXXX(1) = number(rndnum)
number(rndnum) = number(10)
number(10) = XXXX(1)
rndnum = 1 + Int(Rnd() * 9)
XXXX(2) = number(rndnum)
number(rndnum) = number(9)
number(9) = XXXX(2)
rndnum = 1 + Int(Rnd() * 8)
XXXX(3) = number(rndnum)
number(rndnum) = number(8)
number(8) = XXXX(3)
rndnum = 1 + Int(Rnd() * 7)
XXXX(4) = number(rndnum)
number(rndnum) = number(7)
number(7) = XXXX(4)
End Sub
Private Sub cmdOK_Click()
txtInput.SetFocus
Static times As Integer
Static A As Integer
Static B As Integer
A = 0
B = 0
ldlDone.Caption = ""
For Y = 1 To 4
YYYY(Y) = Val(Mid$(txtInput.Text, Y, 1))
Next Y
If YYYY(1) <> YYYY(2) Then
If YYYY(3) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(4) <> YYYY(3) Then
If YYYY(4) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(2) And YYYY(4) <> YYYY(3) Then
For X = LBound(XXXX) To UBound(XXXX)
For Y = LBound(YYYY) To UBound(YYYY)
If XXXX(X) = YYYY(Y) Then
If XXXX(X) = YYYY(X) Then
A = A + 1
Else
B = B + 1
End If
End If
Next Y
Next X
Print YYYY(1) & YYYY(2) & YYYY(3) & YYYY(4), A&; "A" & B & "B"
times = times + 1
If times + 10 Then
cmdOK.Enabled = False
lblTimes.Caption = "你没有机会了,还是看看答案吧!"
times 0
Else
lblTimes.Caption = "你还有" & 10 - times & "次机会"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
txtInput.Text = ""
End Sub
Private Sub cmdanswer_Click()
lblanswer.Caption = XXXX(1) & XXXX(2) & XXXX(3) & XXXX(4)
End Sub 展开
1个回答
展开全部
Option Explicit
'这里只是修改了语法上的错误,逻辑上是否有问题不知道
'修改的地方都加上了*****
Option Base 1
Dim number(10) As Integer
Dim XXXX(4) As Integer
Dim YYYY(4) As Integer
Dim X As Integer
Dim Y As Integer
Dim rndnum As Integer
Private Sub cmdStart_Click()
cmdOK.Enabled = True
lblDone.Caption = "新数字已生成"
lblanswer.Caption = ""
lblTimes.Caption = ""
Call Cls
For X = LBound(number) To UBound(number)
number(X) = X - 1
Next
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Call Randomize
rndnum = 1 + Int(Rnd() * 10)
XXXX(1) = number(rndnum)
number(rndnum) = number(10)
number(10) = XXXX(1)
rndnum = 1 + Int(Rnd() * 9)
XXXX(2) = number(rndnum)
number(rndnum) = number(9)
number(9) = XXXX(2)
rndnum = 1 + Int(Rnd() * 8)
XXXX(3) = number(rndnum)
number(rndnum) = number(8)
number(8) = XXXX(3)
rndnum = 1 + Int(Rnd() * 7)
XXXX(4) = number(rndnum)
number(rndnum) = number(7)
number(7) = XXXX(4)
End Sub
Private Sub cmdOK_Click()
txtInput.SetFocus
Static times As Integer
Static A As Integer
Static B As Integer
A = 0
B = 0
lblDone.Caption = ""'*************
For Y = 1 To 4
YYYY(Y) = Val(Mid$(txtInput.Text, Y, 1))
Next Y
If YYYY(1) <> YYYY(2) Then
If YYYY(3) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(4) <> YYYY(3) Then
If YYYY(4) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(2) And YYYY(4) <> YYYY(3) Then
For X = LBound(XXXX) To UBound(XXXX)
For Y = LBound(YYYY) To UBound(YYYY)
If XXXX(X) = YYYY(Y) Then
If XXXX(X) = YYYY(X) Then
A = A + 1
Else
B = B + 1
End If
End If
Next Y
Next X
Print YYYY(1) & YYYY(2) & YYYY(3) & YYYY(4), A & "A" & B & "B"'**************
times = times + 1
If times = 10 Then'*************
cmdOK.Enabled = False
lblTimes.Caption = "你没有机会了,还是看看答案吧!"
times = 0'***************
Else
lblTimes.Caption = "你还有" & 10 - times & "次机会"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
txtInput.Text = ""
End Sub
Private Sub cmdanswer_Click()
lblanswer.Caption = XXXX(1) & XXXX(2) & XXXX(3) & XXXX(4)
End Sub
'这里只是修改了语法上的错误,逻辑上是否有问题不知道
'修改的地方都加上了*****
Option Base 1
Dim number(10) As Integer
Dim XXXX(4) As Integer
Dim YYYY(4) As Integer
Dim X As Integer
Dim Y As Integer
Dim rndnum As Integer
Private Sub cmdStart_Click()
cmdOK.Enabled = True
lblDone.Caption = "新数字已生成"
lblanswer.Caption = ""
lblTimes.Caption = ""
Call Cls
For X = LBound(number) To UBound(number)
number(X) = X - 1
Next
End Sub
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
Call Randomize
rndnum = 1 + Int(Rnd() * 10)
XXXX(1) = number(rndnum)
number(rndnum) = number(10)
number(10) = XXXX(1)
rndnum = 1 + Int(Rnd() * 9)
XXXX(2) = number(rndnum)
number(rndnum) = number(9)
number(9) = XXXX(2)
rndnum = 1 + Int(Rnd() * 8)
XXXX(3) = number(rndnum)
number(rndnum) = number(8)
number(8) = XXXX(3)
rndnum = 1 + Int(Rnd() * 7)
XXXX(4) = number(rndnum)
number(rndnum) = number(7)
number(7) = XXXX(4)
End Sub
Private Sub cmdOK_Click()
txtInput.SetFocus
Static times As Integer
Static A As Integer
Static B As Integer
A = 0
B = 0
lblDone.Caption = ""'*************
For Y = 1 To 4
YYYY(Y) = Val(Mid$(txtInput.Text, Y, 1))
Next Y
If YYYY(1) <> YYYY(2) Then
If YYYY(3) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(4) <> YYYY(3) Then
If YYYY(4) <> YYYY(1) And YYYY(4) <> YYYY(2) And YYYY(2) And YYYY(4) <> YYYY(3) Then
For X = LBound(XXXX) To UBound(XXXX)
For Y = LBound(YYYY) To UBound(YYYY)
If XXXX(X) = YYYY(Y) Then
If XXXX(X) = YYYY(X) Then
A = A + 1
Else
B = B + 1
End If
End If
Next Y
Next X
Print YYYY(1) & YYYY(2) & YYYY(3) & YYYY(4), A & "A" & B & "B"'**************
times = times + 1
If times = 10 Then'*************
cmdOK.Enabled = False
lblTimes.Caption = "你没有机会了,还是看看答案吧!"
times = 0'***************
Else
lblTimes.Caption = "你还有" & 10 - times & "次机会"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
Else
MsgBox "无效输入!", vbOKOnly, "猜数大师"
End If
txtInput.Text = ""
End Sub
Private Sub cmdanswer_Click()
lblanswer.Caption = XXXX(1) & XXXX(2) & XXXX(3) & XXXX(4)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询