我在名为clsProperties的类模块中创建了一个属性:
Dim blnProduction As Boolean
Public Property Get IsProduction() As Boolean
IsProduction = blnProduction
End Property
Public Property Let IsProduction(ByVal vNewValue As Boolean)
blnProduction = vNewValue
End Property
然后我从表单中调用Let语句:
Private objPropertiesAs New clsProperties
'Determine if we're in production
If (Environ("computername")) = "WS0006" Then
objPropertiesAs.IsProduction = True
Else
objPropertiesAs.IsProduction = False
End If
我使用“WS006”测试代码,IsProduction将等于True。但是,当我尝试访问Get in clsProperties时 IsProduction等于False。
If IsProduction Then
Debug.Print "Prod"
Else
Debug.Print "Dev"
End If
请帮忙!
答案 0 :(得分:0)
您已正确设置clsProperties模块。但是发布的其余代码存在一些问题(因为它不会编译,因此您没有剪切和粘贴实际代码)。这是一个修复问题:
Private objProperties As New clsProperties
objPropertiesAs.IsProduction = (Environ("computername") = "WS0006")
Debug.Print Iif (objProperties.IsProduction, "Prod", "Dev")
我做了一些事情来使你的代码更简洁。我的代码与您的代码之间唯一的实质区别在于,当您执行Get时,您的代码不会引用与IsProduction属性关联的对象。我不知道为什么你没有在那里得到“Object Required”错误,但也许你的代码中有On Error Resume Next
。