开发者

Why is this code snippet not working?

Class GetDate
    Private internal_strDate
    Private internal_strDay
    Private internal_strMonth
    Private internal_strYear
    Private internal_Debug

    Public Property Se开发者_如何学Pythont 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

After my class definition, I have this code and it gives me an error.

Dim objYear
Set objYear = New GetDate
objYear.isdebug(True)

The error says

in debug mode: False Microsoft VBScript runtime error (68, 1) : Object doesn't support this property or method: 'isdebug'

Basically, I want to be able to set the debug to true and then I'm going to modify the GetFormattedDate property to check if 'internal_Debug' is on and if it is then let me enter the date manually. (instead of obtaining the date automagically)


Be sure that you instanced the class properly, like so:

Dim objYear 
Set objYear = New GetDate
objYear.isdebug(True)

Update #1

I misread your code, isdebug is a property, modify your Class a little so the "isdebug" becomes:

Public Property Let isdebug(ByRef vLine)
    internal_Debug = vLine
    WScript.Echo("in debug mode: " & internal_Debug) 
End Property

Then you use it like this:

objYear.isdebug = True

Or, change it to this:

Public Sub isdebug(ByRef vLine)
    internal_Debug = vLine
    WScript.Echo("in debug mode: " & internal_Debug) 
End Sub

Then you can use it like this:

objYear.isdebug(True)


isdebug is a property, so your code should be:

Dim objYear
Set objYear = New GetDate
objYear.isdebug = True

Edit:

Change

Public Property Set isdebug(ByRef vLine)

to

Public Property Let isdebug(ByRef vLine)

Property Set is for objects while Property Let is for value types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜