Absrtact: This paper introduces a method for ASP files to be dynamically included, and the ASP class (class) can be instantiated.
ASP, include file/virtual is handled by priority scripting code, so you cannot use include to dynamically include ASP files. We can use the Execute function to execute the required code dynamically.
Method:
Execute (ASP code)
Example: (vbCrLf for line breaks)
Copy Code code as follows:
Execute ("Class clsabc" &vbCrLf& "public Function output" &vbCrLf& "Response.Write 123" &vbCrLf& ' End Function ' &vbCrLf& ' End Class '
Copy Code code as follows:
Dim OBJABC
Set objabc = New clsabc
Objabc.output
Set objabc = Nothing
Can be used to read from a file or a database of ASP code to execute, note that the code executed should not contain <% and%>
Note Don't confuse with Server.Execute, Server.Execute parameter is ASP virtual path, and use this function not only cannot declare class class dynamically, not even can assign value to main program segment variable.
Example:
main.asp
Copy Code code as follows:
Dim STRABC,OBJABC
STRABC = "Test"
Server.Execute ("sub.asp")
Response.Write STRABC
Set objabc = New clsabc
Objabc.output
Set objabc = Nothing
sub.asp
Copy Code code as follows:
STRABC = "Execute"
Class CLSABC
Public Function output
Response.Write "Class"
End Function
End Class
After the main.asp is executed, only test is output, and OBJABC is not instantiated.