0
我一直在研究一個小型項目,我試圖通過VBA使用類模塊來獲得結果。VBA:類模塊和陣列問題
第一個問題:
下面的語句是從類模塊:
Private xRef As Integer
Private yRef As Integer
Private bValue As Boolean
Private NextTiles(1 To 4, 1 To 4) As Boolean
Public Property Get PreviewTiles(ByVal xRef As Integer, ByVal yRef As Integer) As Boolean
PreviewTiles(xRef, yRef) = NextTiles(xRef, yRef)
End Property
Public Property Let PreviewTiles(ByVal xRef As Integer, ByVal yRef As Integer, ByVal bValue As Boolean)
NextTiles(xRef, yRef) = bValue
End Property
在主要子模塊體,下面的語句存在:
Public P1, P2 As TetrisPlayer
Set P1 = New TetrisPlayer
Set P2 = New TetrisPlayer
...
P1.PreviewTiles(1, 1) = True
MsgBox P1.PreviewTiles(1, 1)
問題1- 這返回說P1.PreviewTiles(1,1)的值應該是真的。
另外第二個問題:
下面下面的代碼是基於一個單獨的子模塊,與所述收集的玩家包括P1和P2(從單獨的子模塊)。
Sub TETRIS_Start(FormName As String)
Dim Player As TetrisPlayer
For Each Player In Players
Call TETRIS_GenerateShape(FormName, Player, True)
Next Player
End Sub
Sub TETRIS_GenerateShape(FormName As String, Player As TetrisPlayer, Start As Boolean)
...
這樣做或多或少好(雖然它遇到問題1)。所以,我想用下面的語句代替調試:
Sub TETRIS_Start(FormName As String)
Call TETRIS_GenerateShape(FormName, P1, True)
End Sub
問題2 - 這將導致對象P1(公開宣佈,我甚至想聲明它在本地)不能夠通過傳遞到子模塊TETRIS_GenerateShape 。
出現的錯誤消息是: 編譯錯誤:ByRef參數類型不匹配。
有什麼建議嗎?
感謝您的編輯,KazJaw。 –