Click to See Complete Forum and Search --> : equivalent to PHP's eval?


jpmoriarty
10-07-2004, 03:48 AM
PHP has a function, eval() (http://uk.php.net/manual/en/function.eval.php), which executes a string as PHP code. It's useful for storing, for example, PHP code in a database and then executing it in a script. Or for allowing people, if you so wished, to enter some php code into a text box on a form and then execute it later on. Risky, but possible.

Does ASP offer a same sort of thing?

I'm desperately trying to find a way to include other files, and thought this might be a way around it! Why, why, WHY ASP doesn't have an equivalent to one of the most useful PHP codes include() (http://uk.php.net/manual/en/function.include.php) I still cannot fathom...

tomhartland
10-07-2004, 05:34 AM
Use the VBScript command Execute() to run the required statement.
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsstmExecute.asp?frame=true)

You can include other files by using the "include" directive...
<!-- #include file="includefile.asp" -->
But note that this is a "pre-processor" type directive, and the file being included cannot be defined by the code (in other words anything such as file=strFile, or file="<%=strFile%>", will not work).

Tom

javaNoobie
10-07-2004, 05:35 AM
If i'm not wrong... its Execute()
Execute("Response.write(""Hello World!!"")")

jpmoriarty
10-07-2004, 06:07 AM
yeah it's that dynamic include that I was trying to do - I thought maybe if I could execute("<!-- include file=strfile -->") that might do the trick. But maybe not.

It just seems so strange to me that the inlcude bit is outside of the ASP structure. It's so handy to be able to do it in PHP...

tomhartland
10-07-2004, 06:20 AM
I agree, it would be incredibly useful (dynamic includes), but it would appear that ASP is not happy to start running through the code until all files have been included. Strange considering it's effectively a parsed language and not compiled.

I spent quite a bit of time trying different ways of including files before I discovered this rather annoying "feature".

If you find a solution, I'd be interested to know how you did it.

javaNoobie
10-08-2004, 02:18 AM
This looks interesting

http://www.webdeveloper.com/forum/showthread.php?s=&threadid=45408

tomhartland
10-08-2004, 03:53 AM
[Oops, I replied to the thread you were quoting - I have replicated the reply here...]

Cool, I wasn't aware of that one :)

Although a quick test shows that page defined variables are not passed through to the executed page, only Server / Application variables.
For example...one.asp
=======
<%
nTom=123
Server.Execute("two.asp")
%>

two.asp
=======
<%=nTom%>
...does not display "123". :(