Class GetDate
Private internal_strDate
Private internal_strDay
Private internal_strMonth
Private internal_strYear
Private internal_Debug
Public Property Set isdebug(ByRef vLine)
internal_Debug = vLine
WScript.Echo("in debug mode: " & internal_Debug)
End Property
Public Property Get GetFormattedDate
internal_strDate = CDate(Date)
internal_strYear = DatePart("yyyy", internal_strDate)
internal_strMonth = DatePart("m", internal_strDate)
internal_strDay = DatePart("d", internal_strDate)
If internal_strMonth < 10 Then
internal_strMonth = "0" & internal_strMonth
End If
If internal_strDay < 10 Then
internal_strDay = "0" & internal_strDay
End If
GetFormattedDate = internal_strYear & "-" & internal_strMonth & "-" & internal_strDay
End Property
End Class
在我的类定义之后,我有这段代码,它给了我一个错误。
Dim objYear
Set objYear = New GetDate
objYear.isdebug(True)
错误提示
in debug mode: False Microsoft VBScript runtime error (68, 1) : Object doesn't support this property or method: 'isdebug'
基本上,我希望能够将调试设置为 true,然后我将修改 GetFormattedDate 属性来检查“internal_Debug”是否打开,如果打开,则让我手动输入日期。 (而不是自动获取日期)
最佳答案
确保您正确实例化了该类,如下所示:
Dim objYear
Set objYear = New GetDate
objYear.isdebug(True)
更新#1
我误读了你的代码,isdebug是一个属性,稍微修改一下你的类,这样“isdebug”就变成了:
Public Property Let isdebug(ByRef vLine)
internal_Debug = vLine
WScript.Echo("in debug mode: " & internal_Debug)
End Property
然后你像这样使用它:
objYear.isdebug = True
或者,将其更改为:
Public Sub isdebug(ByRef vLine)
internal_Debug = vLine
WScript.Echo("in debug mode: " & internal_Debug)
End Sub
然后你可以像这样使用它:
objYear.isdebug(True)
关于debugging - 为什么这个代码片段不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7040184/