In classic ASP is it possible to create an END sub

2019-08-21 07:04发布

I created a class in asp and wanted to know if it was possible to create a function or sub named "END". Is this possible even as a sub or function. The reason I wanted to call this for my class instance or class module like MyClass.End is to then call response.end?

Or is it possible to overide the response.end function to first check something before ending?

class Myclass

sub write(dim str)
      response.write(str)
end write

' Is this "END" possible?
sub end
   response.end
end sub

End class

2条回答
Luminary・发光体
2楼-- · 2019-08-21 07:19

Correction

This is not a valid subroutine declare : sub write(dim str)
Dim statement cannot be used to declare parameters. You should use ByRef or ByVal. Default is ByRef if not specified.
And end write should be end sub.
See instructions from MSDN : Sub Statement

Trick

When you need to use a reserved keyword for property or method name in the classes, you can declare it with brackets. Then you can call without brackets. Here the example:

Class Myclass

    Sub Write(str)
        Response.Write str
    End Sub

    Sub [End] 'with brackets
       Response.End
    End Sub

End Class

Set o = New Myclass
    o.write "what's up?"
    o.end 'without brackets

Response.Write "..." 'this will not be printed
查看更多
Rolldiameter
3楼-- · 2019-08-21 07:34

end is a reserved word for vbscript (what classic ASP is based on) so no. This is a list of reserved words... http://support.microsoft.com/kb/216528

查看更多
登录 后发表回答