Local Variables and subroutines
Good software design methodologies require that the solution be
modular with well documented interfaces and data hiding where
possible. We utilize subroutines to help solve pieces of the overall
problem. The following examples demonstrates how to define 2 subroutines
in VBscript and define local variables which are hidden from outside
subroutines.
<html>
<head>
<Title> subroutines</title>
</head>
<body>
<% sub Procedure_1()
strDifferent="Hi I'am strDifferent in Procedure_1"%>
<%=strDifferent%>
<%End sub%>
<% sub Procedure_2()
strDifferent="Hi I'am strDifferent in Procedure_2"%>
<%=strdifferent%>
<%End sub%>
<P> Calling Procedure 1 ..<I><%Procedure_1()%> </i></P>
<P> Calling Procedure 2 ..<I><%Procedure_2()%> </i></P>
<P> Calling Procedure 1 ..<I><%Procedure_1()%> </i></P>
</body>
</html>
You see the result:
Calling Procedure 1 ..Hi I'am strDifferent in Procedure_1
Calling Procedure 2 ..Hi I'am strDifferent in Procedure_2
Calling Procedure 1 ..Hi I'am strDifferent in Procedure_1
How it works:
Each subroutines Procedure_1 and procedure_2 define their own copies
of strDifferent and assign different values to thereby demonstrating
how to create a local variable and the scope of that variable.
|