【发布时间】:2014-01-13 02:35:38
【问题描述】:
我一直在做一个小项目,我尝试通过 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 的集合 Players(来自单独的子模块)。
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 参数类型不匹配。
有什么建议吗?
【问题讨论】:
标签: arrays class vba object module