求助!我是初学者,需要大家指教。

Smallfrogs 2001-07-18 10:32:30
求助!

本人由于刚刚开始学习VB 6,有许多地方不明白,这不,刚刚编制的一个游戏---“猜数字”(来源于文曲星的那个猜数字游戏)就是无法成功运行。请大家帮我看看,哪里编错了??

设计思路:先加入一个command button,然后复制9个建立数组,caption分别为0--9,再加入2个command button分别的caption为"确定"和"取消"。还加入1个frame,1个list,1个lable,最后编辑菜单:新游戏、显示答案和结束。按照如此操作以后编制源代码,完成后可以编译,可是无法正常运行,就是说根本不能够像文曲星那样玩。特此求大家指正代码种的错误。

源代码如下:
Dim PcA, PcB, PcC, PcD As Integer
Dim UserA, UserB, UserC, UserD As Integer
Dim Degree As Integer
Dim Num As Integer
Private Sub Form_Load()
For i = 0 To 9
Command1(i).Enabled = False
Next i
Command2.Enabled = False
Command3.Enabled = False
View.Enabled = False
End Sub
Private Sub Newgame_click()
View.Enabled = True
List2.Clear
Degree = 0
Randomize
Num = 1
Label1.Caption = 0 & "A" & 0 & "B"
PcA = Int(9 * Rnd)
Do
PcB = Int(9 * Rnd)
Loop While PcB = PcA
Do
PcC = Int(9 * Rnd)
Loop While PcC = PcA Or PcC = PcB
Do
PcD = Int(9 * Rnd)
Loop While PcD = PcA Or PcD = PcB Or PcD = PcC
For i = 0 To 9
Command1(i).Enabled = True
Next i
Command2.Enabled = False
Command3.Enabled = True
End Sub
Private Sub Command1_click(Index As Integer)
If Num <= 4 Then
Command1(Index).Enabled = False
End If
If Num = 4 Then
Command2.Enabled = True
End If
Select Case Index
Case 0
UserEnter (0)
Case 1
Case 2
Case 3
Case 4
Case 5
Case 6
Case 7
Case 8
Case 9
End Select
End Sub
Private Sub Command2_Click()
Dim A, B As Integer
A = 0
B = 0
Degree = Degree + 1
If UserA = PcA Then
A = A + 1
ElseIf UserA = PcB Or UserA = PcC Or UserA = PcD Then
B = B + 1
End If
If UserB = PcB Then
A = A + 1
ElseIf UserB = PcA Or UserB = PcC Or UserB = PcD Then
B = B + 1
End If
If UserC = PcC Then
A = A + 1
ElseIf UserC = PcA Or UserC = PcB Or UserC = PcD Then
B = B + 1
End If
If UserD = PcD Then
A = A + 1
ElseIf UserD = PcA Or UserD = PcB Or UserD = PcC Then
B = B + 1
End If
Lable1.Caption = A & "A" & B & "B"
List2.AddItem UserA & UserB & UserC & UserC & UserD & " " & Lable1.Caption
Command2.Enabled = False
For i = 0 To 9
Command1(i).Enabled = True
Next i
Num = 1
If A = 4 Then
MsgBox "正确!" & "你一共猜了" & Degree & "次"
For i = 0 To 9
Command1(i).Enabled = False
Next i
Command2.Enabled = False
End If
End Sub
Private Sub Command3_click()
Num = 1
For i = 0 To 9
Command1(i).Enabled = Ture
Next i
Command2.Enabled = False
End Sub
Private Sub View_click()
MsgBox "答案是:" & PcA & PcB & PcC & PcD & "你答对了吗?"
End Sub
Private Sub End_Click()
Unload Me
End Sub
Sub UserEnter(i)
If Num = 1 Then
UserA = i
Num = Num + 1
ElseIf Num = 2 Then
UserB = i
Num = Num + 1
ElseIf Num = 3 Then
UserC = i
Num = Num + 1
ElseIf Num = 4 Then
UserD = i
Num = Num + 1
Else: MsgBox "只能够输入4位数!"
End If
End Sub
...全文
168 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
Smallfrogs 2001-07-20
  • 打赏
  • 举报
回复
谢谢大家!现在程序已经通过,如果大家要的话,请到http://go7.163.com/smallfrogs/guess.zip下载
mostar 2001-07-19
  • 打赏
  • 举报
回复
比我刚刚学的时候强多了,努力!:-)
forhui 2001-07-19
  • 打赏
  • 举报
回复
我修正的代码如下,但我不知这个游戏怎样玩?也不知改对没有?
Dim PcA, PcB, PcC, PcD As Integer
Dim UserA, UserB, UserC, UserD As Integer
Dim Degree As Integer
Dim Num As Integer
Private Sub Form_Load()
For i = 0 To 9
Command1(i).Enabled = False
Next i
Command2.Enabled = False
Command3.Enabled = False
view.Enabled = False
End Sub
Private Sub Newgame_click()
view.Enabled = True
List1.Clear
Degree = 0
Randomize
Num = 1
Label1.Caption = 0 & "A" & 0 & "B"

PcA = Int(9 * Rnd)

Do
PcB = Int(9 * Rnd)
Loop While PcB = PcA

Do
PcC = Int(9 * Rnd)
Loop While PcC = PcA Or PcC = PcB

Do
PcD = Int(9 * Rnd)
Loop While PcD = PcA Or PcD = PcB Or PcD = PcC

For i = 0 To 9
Command1(i).Enabled = True
Next i

Command2.Enabled = False
Command3.Enabled = True

End Sub
Private Sub Command1_click(Index As Integer)
If Num <= 4 Then
Command1(Index).Enabled = False
End If
If Num = 4 Then
Command2.Enabled = True
End If
Select Case Index
Case 0
UserEnter (0)
Case 1
UserEnter (1)
Case 2
UserEnter (2)
Case 3
UserEnter (3)
Case 4
UserEnter (4)
Case 5
UserEnter (4)
Case 6
UserEnter (6)
Case 7
UserEnter (7)
Case 8
UserEnter (8)
Case 9
UserEnter (9)
End Select
End Sub
Private Sub Command2_Click()
Dim A, B As Integer
A = 0
B = 0
Degree = Degree + 1
If UserA = PcA Then
A = A + 1
ElseIf UserA = PcB Or UserA = PcC Or UserA = PcD Then
B = B + 1
End If
If UserB = PcB Then
A = A + 1
ElseIf UserB = PcA Or UserB = PcC Or UserB = PcD Then
B = B + 1
End If
If UserC = PcC Then
A = A + 1
ElseIf UserC = PcA Or UserC = PcB Or UserC = PcD Then
B = B + 1
End If
If UserD = PcD Then
A = A + 1
ElseIf UserD = PcA Or UserD = PcB Or UserD = PcC Then
B = B + 1
End If
Label1.Caption = A & "A" & B & "B"
List1.AddItem UserA & UserB & UserC & UserC & UserD & " " & Label1.Caption
Command2.Enabled = False
For i = 0 To 9
Command1(i).Enabled = True
Next i
Num = 1
If A = 4 Then
MsgBox "正确!" & "你一共猜了" & Degree & "次"
For i = 0 To 9
Command1(i).Enabled = False
Next i
Command2.Enabled = False
End If
End Sub
Private Sub Command3_click()
Num = 1
For i = 0 To 9
Command1(i).Enabled = Ture
Next i
Command2.Enabled = False
End Sub
Private Sub View_click()
MsgBox "答案是:" & PcA & PcB & PcC & PcD & "你答对了吗?"
End Sub
Private Sub End_Click()
Unload Me
End Sub
Sub UserEnter(i)
If Num = 1 Then
UserA = i
Num = Num + 1
ElseIf Num = 2 Then
UserB = i
Num = Num + 1
ElseIf Num = 3 Then
UserC = i
Num = Num + 1
ElseIf Num = 4 Then
UserD = i
Num = Num + 1
Else: MsgBox "只能够输入4位数!"
End If
End Sub
forhui 2001-07-19
  • 打赏
  • 举报
回复
Private Sub Command1_click(Index As Integer)
你添加控件数组了吗?

你程序的到处都是错,我真的很难一一指出。
你如果真的有心学VB,研究一下VB5的联机帮助吧。(要装VB5)
我觉得,它是本很好的教材。
benlovekelly 2001-07-19
  • 打赏
  • 举报
回复
阿呆的程序应该就是文曲星上那种玩法。我同意!
benlovekelly 2001-07-19
  • 打赏
  • 举报
回复
一个过程的长度最好不要超过一页,否则读起来太累了!!(建议)
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
分数!
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
使用说明:按下F2开始游戏。游戏规则:输入4个数字(每次输入4个数字,输入以后请按下确定),如果在这个数字当中,位置和数字均和电脑给出的一样,那么得A;如果只有数字正确而位置不正确,那么得B。当出现4A时猜对!

这就是说明。
forhui 2001-07-19
  • 打赏
  • 举报
回复
我又不知这个游戏怎样玩,你又不讲一下,我很难改对的。
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
阿呆:不对啊!我输入4个数字,但是在list中出现5个数字。而且第3和第4位重复。本来应该只有4个数字,否则这个游戏无法玩!
forhui 2001-07-19
  • 打赏
  • 举报
回复
我晕!
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
大家查分吧!
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
谢谢forhui。程序运行成功。另外如何给分?我还不会。
forhui 2001-07-19
  • 打赏
  • 举报
回复
喂!兄弟,不要忘了给分啊!
Smallfrogs 2001-07-19
  • 打赏
  • 举报
回复
谢谢大家!!
forhui 2001-07-18
  • 打赏
  • 举报
回复
这个“猜数字”游戏怎样玩,能简要讲一下吗?
Smallfrogs 2001-07-18
  • 打赏
  • 举报
回复
哦!我刚刚开始学习嘛。
forhui 2001-07-18
  • 打赏
  • 举报
回复

你的代码可读性太差,改良一下编程风格吧!
Smallfrogs 2001-07-18
  • 打赏
  • 举报
回复
经过实验,还是无法运行。
Smallfrogs 2001-07-18
  • 打赏
  • 举报
回复
谢谢!
加载更多回复(1)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧