许如云方杰改编:哪位好心人有空,帮我看看这段代码,哪出错了?!~先谢谢了~

来源:百度文库 编辑:高考问答 时间:2024/05/03 21:08:06
哪位好心人有空,帮我看看这段代码,哪出错了?!~先谢谢了~

这是一个纸牌游戏,pokers类已经定义,有imge,color,number三个属性
每次运行到*号行时总报错:对象变量或with块变量未设置
哪位大哥大姐帮帮我呀~~mycards(i)从来没有被释放成nothing啊?!~
先谢谢了~! 先谢谢了~! 先谢谢了~!先谢谢了~!先谢谢了~!先谢谢了~!先谢谢了~!先谢谢了~!先谢谢了~!
代码:
Option Explicit
Dim OriginalPokers(1 To 54) As pokers
Dim WashedPokers(1 To 54) As pokers
Dim MyCards(1 To 20) As pokers
Dim C1Cards(1 To 20) As pokers
Dim C2Cards(1 To 20) As pokers
Dim picname As String
Dim i As Integer
Dim l As Integer
Dim m As Integer
Dim n As Integer
Sub Shuffle()
Randomize
Dim temp As pokers
Dim r As Integer
For i = 1 To 54
r = Int(Rnd * 54 + 1)
Set WashedPokers(i) = OriginalPokers(i)
Set temp = WashedPokers(i)
Set WashedPokers(i) = WashedPokers(r)
Set WashedPokers(r) = temp
Next
End Sub
Sub InitPokers()
For i = 1 To 54
Set OriginalPokers(i) = New pokers

OriginalPokers(i).Image = Trim(Str(i)) & ".jpg"
Select Case i
Case 1 To 13
OriginalPokers(i).Color = "Heart"
Case 14 To 26
OriginalPokers(i).Color = "Spade"
Case 27 To 39
OriginalPokers(i).Color = " Diamond"
Case 40 To 52
OriginalPokers(i).Color = "plocx"
Case 53 To 54
OriginalPokers(i).Color = "Ghost"
End Select
Next
End Sub

Sub Deal()
l = 1
m = 1
n = 1
For i = 1 To 20
Set MyCards(i) = New pokers
Next
For i = 1 To 51
If i Mod 3 = 0 Then
Set MyCards(l) = WashedPokers(i)
l = l + 1
End If
If i Mod 3 = 1 Then
Set C1Cards(m) = WashedPokers(i)
m = m + 1
End If
If i Mod 3 = 2 Then
Set C2Cards(n) = WashedPokers(i)
n = n + 1
End If
Next

End Sub
Sub Display()

For i = 1 To 17
Load Image1(i)
Image1(i).Left = Image1(i - 1).Left + Image1(0).Width / 5
Image1(i).Top = Image1(0).Top
Image1(i).Picture = LoadPicture(App.Path & "\" & MyCards(i).Image) **************************
Next
End Sub
Private Sub Form_Load()
InitPokers
Shuffle
Deal
Display
End Sub
pokers类已在类模块里定义,只有几行代码:
public image as string
public color as string
public number as integer

pokers绝对不是VB的数据类型,建议用自定义类定义pokers这个对象,可在窗体模块或标准模块中定义:
Public(Private) Type pokers
image as string
color as string
number as integer
End Type

能把整个VB代码贴出马?方便调试