Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables within a #include

Status
Not open for further replies.

pwel

Programmer
Aug 18, 1999
79
GB
Hi people,

Does anyone know of way to use variables within a #include statement??? What I want to do is, based on the value of a variable pulled from the QueryString, I want to include certain files.

I originally had a Select...Case statement to construct the variable myFileName, but the list was getting long.....

It would be great if the following would work!!

<!-- #include file=&quot; & myFileName & &quot;-->

But it doesn't work, as I have tried it.

Any Ideas???????

Cheers.
 
There are a couple things that you can do.

if you are including a file that doesn't have any ASP code, you can always just use the FSO to dynamically read the file, then output the contents of the string.
Check my FAQ on reading/writing files for more info on this.

if you do have asp code that needs to get executed, you can use Server.Execute to execute whatever is on the ASP page. The drawback to this method is that your calling page doesn't get any access to the functions or variables within that .Executed page.

see

for more details.

otherwise, you are just stuck with the old

<%if something then%>
<!--#include file=&quot;blah.asp&quot;-->
<%elseif somethingelse then%>
<!--#include file=&quot;blah2.asp&quot;-->
<%end if%>

hope this helps
leo
 
All ASP code, including INCLUDES, is extracted by the preprocessor before any of it is executed. Therefore nothing in the input data can affect the contents of the ASP code used to accept the input.
 
<%
myFileName = Request.QueryString(&quot;YourFile&quot;)
%>
<!-- #include file=<%=myFileName>-->


or

<%
myFileName = Request.QueryString(&quot;YourFile&quot;)

Response.Write &quot;<!-- #include file=&quot; & myFileName & &quot;-->&quot;
%>
Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
I think you will find that both of those examples do NOT work!!!!!
 
Tim Larkin. As I can see, you are stupid not the guy who asked you. You cannot put the INCLUDE directive in the script delimeters. Include directive is executed before any ASP code on the page. So, if you don't know smth,; don't say that and don;t call people stupid causze you can be dumb yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top