Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class Structure in classic asp

Tags:

asp-classic

I need to use class structure in classic asp. I have written following three classes.

Category.asp

<%

Class Category

    Private NameVar

    Public Property Get Name()
        Name = NameVar
    End Property

    Public Property Let Name(nameParam)
        NameVar = nameParam
    End Property

End Class

%>

Item.asp

<%

Class Item

    Private NameVar
        Private CategoryVar

    Public Property Get Name()
        Name = NameVar
    End Property

    Public Property Let Name(nameParam)
        NameVar = nameParam
    End Property

    Public Property Get Category()
        category = categoryVar
    End Property

    Public Property Let Category(categoryParam)
    CategoryVar = categoryParam
    End Property

End Class

%>

Test.asp

<%

    Dim CategoryVar
    Set CategoryVar = New Category

    CategoryVar.Name = "Weight"

    Dim ItemVar
    Set ItemVar = New Item

    ItemVar.Name = "kg"
    ItemVar.Category = CategoryVar

%>
<html>
    <head>
        <title>UoM Componet Testing</title>
    </head>
    <body>
        <%= ItemVar.Name %><br/>
    </body>
</html>

When I run this code, I have found some problem. Error is:

Microsoft VBScript runtime (0x800A01B6) Object doesn't support this property or method: 'CategoryVar'".

How can explain this? Please help me.

like image 221
zanhtet Avatar asked Jan 09 '12 09:01

zanhtet


1 Answers

In VBScript, if you know that a property will contain an object reference, you must define it using the Property Set statement. Furthermore, you must use the Set statement when assigning object references to variables. With that in mind, the following changes need to be made:

Item.asp

Class Item

    '<snip>

    Public Property Get Category()
        ' Add Set here
        Set category = categoryVar
    End Property

    ' Change "Property Let" to "Property Set"
    Public Property Set Category(categoryParam)
        Set CategoryVar = categoryParam
    End Property

End Class

Test.asp

<%
    ' <snip>    

    ItemVar.Name = "kg"
    Set ItemVar.Category = CategoryVar

%>
like image 60
Cheran Shunmugavel Avatar answered Nov 14 '22 21:11

Cheran Shunmugavel