示例代码示例:

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
如何解决? (还有奖金-为什么会发生?)谢谢

最佳答案

请引用 Property Let 的文档。 Property Let与子例程调用不同。正确的语法是

obj.EnvFlags(0) = True

09-27 12:45