0

用于说明的示例代码:

Option Explicit
Dim obj: Set obj = New Foo
WScript.Echo "EnvFlags(0)=" & obj.EnvFlags(0) 'EnvFlags(0)=False
WScript.Echo Join(obj.EnvFlags(-1), ",")      'False,False,False

On Error Resume Next 'enabled just for facility's sake
obj.EnvFlags 0, True '<< Why this NOT work?...
If Err Then WScript.Echo Err.Number, Err.Description
'> 450 Wrong number of arguments or invalid property assignment
On Error Goto 0

Class Foo
    Private mEnvFlags

    Public Property Let EnvFlags(nIndex, bValue)
        If vbBoolean <> VarType(bValue) Then Exit Property
        If nIndex >= 0 And nIndex <= 2 Then
            mEnvFlags(nIndex) = bValue
        End If
    End Property

    Public Property Get EnvFlags(nIndex)
        If nIndex < 0 Or nIndex > 2 Then
            EnvFlags = mEnvFlags
        Else
            EnvFlags = mEnvFlags(nIndex)
        End If
    End Property

    Private Sub Class_Initialize
        mEnvFlags = Array(False, False, False)
    End Sub
End Class

如何解决?(作为奖励 - 为什么会发生?)谢谢

4

1 回答 1

3

参考文档Property Let。AProperty Let与子程序调用不同。正确的语法是

obj.EnvFlags(0) = True
于 2013-03-13T04:04:04.990 回答