在经典的ASP中,可以创建END子函数吗? [英] In classic ASP is it possible to create an END sub or function?
问题描述
我在asp中创建了一个类,想知道是否可以创建一个名为"END"的函数或子类.这可能是子功能吗?我想为我的类实例或类模块(例如MyClass.End)调用此函数的原因是然后调用response.end?
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?
还是可以覆盖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
推荐答案
更正
这不是有效的子例程声明:sub write(dim str)
Dim 语句不能用于声明参数.您应该使用 ByRef 或 ByVal .如果未指定,默认值为ByRef.
并且end write
应该是end sub
.
请参阅MSDN上的说明:子语句
把戏
当您需要在类中的属性或方法名称中使用保留关键字时,可以使用方括号将其声明.然后,您可以不带括号的情况下通话.
这里是示例:
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
这篇关于在经典的ASP中,可以创建END子函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!