Hi
clarkin
Can you use Server.Execute() to call a function? Can you pass in parameters and get a value returned?
Yes and No.
Life would be great if you could but the only way to get it to work with this functionality
is to use session objects as the parameters. Obviously that can get resource hungry real fast
seeing as includes and server.execute themselves take a lot of resources due to caching issues.
I'm kind of excited because I think this is a great topic to discuss and something of a
discussion it seems we've gone away from lately,. (in discussing anything really)
So to stack this up on the sessions provided our resources are not dragged down the drain
and we're starring at a blank screen for a bit
![[lol] [lol] [lol]](/data/assets/smilies/lol.gif)
this is a great way to actually perform
minor to moderate tasks that will make 1) the pages (scripts) more structured and 2) far easier
for later maintenance and debugging.
let's say we make a page named exampleExecuteOne.asp
this page will have nothing but a form and a If statement to conditionally call the execute
Now here's the gotcha! You don't really want to use this method out of a conditional statement.
at least I've not liked to in the past. It makes error handling a bit cumbersome and you
may cause issues with the view of the outputted page as a value can effectively be sent empty
to your page. Although as everything a few conditional expressions can get you out of things
of that matter. anyhow, onto the first page
short and to the point for our example
steps in sequential line
1) client function to set submission
2) conditional check if submission occurred
3) load form if not
4) set session values
5) execute the function in second page
6) all done
<html>
<head>
<script language="javascript">
function subFrm() {
frm.submitted.value = "subbed";
return true;
}
</script>
</head>
<body>
<%
If Request.Form("submitted"

= "" Then
%>
<form name="frm" method="POST" onSubmit="return subFrm()">
<input type="hidden" name="submitted">
<input type="text" name="myName">
<input type="submit" value="Sub It!">
</form>
<%
Else
Dim TheName : TheName = Request.Form("myName"

Session("TheName"

= TheName
Server.Execute("myFunctions.asp"
End If
%>
</body>
</html>
obviously looking at this the only thing I think we get out of it is structure to
the page and ease of reading for everyone that may follow. That is a major part
of structured programming though and I am a strong believer in doing things like this
to make it easier for the next programmer.
so the second page being our function we do a simple
name: myFunctions.asp (you can use a .inc I believe also)
<%
Function playWithValues(TheName)
If Len(TheName) <= 0 Then
Response.Write "Sorry, the was a error in the passing of your name<br>"
Else
Response.Write "Good morning <strong>" & TheName & "</strong>"
End If
End Function
playWithValues(Session("TheName"

)
%>
now in this case we'll always output something, but to make this really fucntional and
useful a check for empty, isNull(), Len etc. in the session var could be done to exit the
function prior to any calc's or output. That would be obviously the proper and most likely
use for this method. something like
wow! that was a bunch of blabbing.
![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)
<%
Function playWithValues(TheName)
If Len(TheName) <= 0 Then
Response.Write "Sorry, the was a error in the passing of your name<br>"
Else
Response.Write "Good morning <strong>" & TheName & "</strong>"
End If
End Function
If session("TheName"
<> "" Then
playWithValues(Session("TheName"
)
End If
%>
hope that helps out in the future when you think of something you need like this.
onpnt
_____________________________________________________________________