Forums
This topic is locked
End Code Execution from Sub Procedure?
Posted 16 May 2003 23:30:57
1
has voted
16 May 2003 23:30:57 Brian Canterbury posted:
Hello all,I am writing an ASP page in which I am calling a sub procedure. After the code in the sub procedure executes, I do <b>not </b> want to return to the code that called the sub. In other words, I would like ALL code execution for the page to end if the Sub procedure has run. How do I do this. I am reasonably new to ASP and I am not sure what statements will do this.
Will someone help me?
Edited by - knottydrd on 16 May 2003 23:32:02
Replies
Replied 17 May 2003 22:05:43
17 May 2003 22:05:43 Matthew Maguire replied:
Hi knottydrd,
When you call a sub proceedure the server will execute the proceedure and will continue from where it left off on the page. I cannot see a way change this.
However, with some simple code we can create exactly what you want.
1) At the beginning of your file define a new variable, such as "procload", by entering the following:
Dim procload
2) At the beginning of your sub proceedure, give the variable the value "loaded", by entering the following:
procload = "loaded"
The idea is, if the sub proceedure has been executed then variable 'procload' will have the value 'loaded', and the sub proceedure hasn't been loaded the variable won't have any value at all. Therefore, we can tell if the proceedure has been executed by the status of the varibale, and by using an "if ... then" command can tell it to execute more code or none.
3) Go to the point where you call the proceedure. On the line immediately below the call command enter the following:
If NOT procload = "loaded" then
' Put in the code you want processed if the proceedure is not called. Below this code, enter the following:
End if
The server will only processes the code between the "If ... then" and "End if" if the proceedure has not been called.
I hope this helps.
Matthew Maguire
When you call a sub proceedure the server will execute the proceedure and will continue from where it left off on the page. I cannot see a way change this.
However, with some simple code we can create exactly what you want.
1) At the beginning of your file define a new variable, such as "procload", by entering the following:
Dim procload
2) At the beginning of your sub proceedure, give the variable the value "loaded", by entering the following:
procload = "loaded"
The idea is, if the sub proceedure has been executed then variable 'procload' will have the value 'loaded', and the sub proceedure hasn't been loaded the variable won't have any value at all. Therefore, we can tell if the proceedure has been executed by the status of the varibale, and by using an "if ... then" command can tell it to execute more code or none.
3) Go to the point where you call the proceedure. On the line immediately below the call command enter the following:
If NOT procload = "loaded" then
' Put in the code you want processed if the proceedure is not called. Below this code, enter the following:
End if
The server will only processes the code between the "If ... then" and "End if" if the proceedure has not been called.
I hope this helps.
Matthew Maguire