我有一个名为PLAYER的自定义类,该类具有以下属性以及相关的getter和setter以及默认的init。
Private aName As String
Private aAge As Integer
Private aID As String
Private aScore As Integer
我现在正尝试在主程序中创建一个数组,如下所示:
Dim Players As Range
Set Players = Range("PLAYERS")
Dim PlayerRows As Integer, PlayerCols As Integer, count As Integer
PlayerRows = Players.Rows.count
Dim allPlayers() As PLAYER
ReDim allPlayers(5)
Dim temp As New PLAYER
temp.name = Players.Cells(count + 1, 1)
temp.age = Players.Cells(count + 1, 2)
temp.ID = Players.Cells(count + 1, 3)
temp.score = Players.Cells(count + 1, 4)
allPlayers(0) = temp
但是当我尝试将新对象添加到播放器对象数组时,出现运行时错误91'对象变量或未设置块变量'。
我如何错误地设置此阵列?我正在尝试为PLAYER类提供一个数组。
答案 0 :(得分:1)
要处理对象,您必须使用“ Set”关键字:
Set allPlayers(0) = temp