Forum Moderators: open
Here's an example:
MyInclude.asp
<%
sub MySub()
Var1 = "foo"
Var2 = "bar"
End Sub
%>
MyPage.asp
<!--include file="MyInclude.asp"-->
<%
Call MySub()
Response.write Var1 & Var2
%>
Although MySub has no arguments and can't return a value, after it's called two variables automagically appear. Amazing! I've also come across similar subroutines that create connections, recordsets, etc.
Now, if I'm not mistaken a Sub is Public by default, but IMHO no arguments and creating variables to use outside the scope of the sub is just asking for trouble. Is this some old school technique or just plain bad coding?
Well, although VBscript apparently makes this kind of statement possible, it doesn't score high marks for readability.
A possible refactoring is to create a method that returns a class that contains the properties that are needed on each page (Var1, Var2).