Støv, fibre og metalliske partikler kan påvirke både uptime, levetid og driftssikkerhed. Derfor arbejder flere datacentre systematisk med contamination control.
Whether you just started to learn ASP or you are an ASP expert, you've definitely dealt with both Local and Global variables at one point or another. For the benefit of those who are learning ASP, we'll go ahead and explain what Local and Global variables are; for those who are ASP experts, this will be a refresher. Let's get started.
Keep the following in mind: If you assign a value to a variable and then assign another value to the same variable, then the old value will be replaced with the new one - that is not the case with Local variables.
Local Variables
Local variables are variables that exist only during the lifetime of the procedure that created them. In other words, once a procedure has stopped running (has finished what it was supposed to do), the variable that was created at the beginning of the procedure ceases to exist therefore you can assign different values to the same variable. Let's see an example of how they work (variables are in green) - this script will go in the BODY of your HTML document.
<% Sub Procedure_1 ( ) strText = "'This is a text string"%> <%=strText%> <%End Sub%>
<% Sub Procedure_2 ( ) strText = "This is another text string"%> <%=strText%> <%End Sub%>
<p>This is the result for the first procedure: <%Procedure_1( )%></p> <p>This is the result for the second procedure: <%Procedure_2 ( )%></p> <p>This is the result for the first procedure: <%Procedure_1( )%>, again."%>
See it in action
As you can see, strText ceased to exist once the first procedure finished executing thus you could assign a new value to the same variable in the second procedure. The "old" value of the variable could be called again if the first procedure is once again invoked - as it is shown in the example.
Global variables unlike Local Variables, persist throughout the lifetime of the script, not a procedure. In other words, they last for as long as the script is running. Let's see how they work.
<%strGlobal = "Global variables persist during the lifetime of the script."%> <%=strGlobal%>
<% Sub Procedure_1 ( ) strText = "'This is a text string"%> <%=strText%> <%=strGlobal%> <%End Sub%>
<% Sub Procedure_2 ( ) strText = "This is another text string"%> <%=strText%> <%=strGlobal%> <%End Sub%>
<p>This is the result for the first procedure: <%Procedure_1( )%></p> <p>This is the result for the second procedure: <%Procedure_2 ( )%></p> <p>This is the result for the first procedure: <%Procedure_1( )%>, again."%>
Use local variables, and avoid public variables. Local variables can be accessed quicker by the ASP scripting engine than public variables, because the entire namespace doesn't have to be searched.
Det er for fedt at der findes folk som dig, som gider hjælpe folk som mig. Hvis du forstår hvad jeg mener :-)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.