In classic ASP is it possible to create an END sub or function?

可紊 提交于 2019-12-25 09:34:06

问题


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

回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/8883697/in-classic-asp-is-it-possible-to-create-an-end-sub-or-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!