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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to include files with VBscript 1

Status
Not open for further replies.

LinuxKommy

Technical User
Apr 2, 2002
31
US
I use two different files depending on a session variable, but when i put the include tags into script, it writes the tags but does not include the files. what am i doing wrong? the code is pasted below

<%
if Session(&quot;P&quot;)=&quot;24&quot; or Session(&quot;P&quot;)=&quot;29&quot; then
response.write &quot;<!--#include file='CAR_1.inc'-->&quot;
else
response.write &quot;<!--#include file='CAR_2.inc'-->&quot;
end if
%>

Thanks
 
Do it like this

<%
if Session(&quot;P&quot;)=&quot;24&quot; or Session(&quot;P&quot;)=&quot;29&quot; then
%>
<!--#include file='CAR_1.inc'-->
<%
else
%>
<!--#include file='CAR_2.inc'-->
<%
end if
%>
 
Thanks! This worked like a charm, but how does the script get processed before the includes?

I was told that scripts get processed after includes.

Thanks again
 
Nope I use this all the time. Includes are processed in the order of the ASP code. So if you always want to include a particular file put it at the top of your coide before your <%.
 
I have a similar problem, only instead of a choice of 2 include components, I have a choice of over 40!

The user enters a choice which is stored in variable str_CountyName - I then get VBScript to build an include link as follows

<%
Dim str_IncLink
str_IncLink=&quot;<Object data=&quot;&quot;counties/&quot;
str_IncLink=str_IncLink+str_CountyName
str_IncLink=str_IncLink+&quot;.asp&quot;&quot;></object>&quot;

Response.Write (str_IncLink)

%>

The variable str_IncLink ends up looking like this

<!--#include file=&quot;counties/rutland.asp&quot; -->

which is the page I want to include on the master page. It makes this line correctly and puts it in to the HTML, but the component page (counties/rutland.asp in this case) doesn't load, the include line is sent to the browser instead.

Anyone got any ideas?

Confused of England
 
include files (path) or any portion cannot be in your ASP script. you can't use a variable in any way.
the closest logic to something of that effect is to do a conditional statement as
<%
If this = that Then
%>
<!--#include file=&quot;counties/rutland.asp&quot; -->
<%
Else
%>
<!--#include file=&quot;counties/rutland.asp&quot; -->
<%
End If
%>


On a side note:
Please post ASP related content in the ASP Forum forum333. Let's keep the forums to their related subject and clean with subject related content

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924

onpnt2.gif
 
Hummm, 40+ include statements just to throw all but one away, the server administrators are gonna love that!

While I was going back through old posts I came across the <IFrame> tag that does the job, though i'm not sure this is the best way to do the job.

The code now looks like:-

<%
Dim str_IncLink
str_IncLink=&quot;<IFrame src=&quot;&quot;counties/&quot;
str_IncLink=str_IncLink+str_CountyName
str_IncLink=str_IncLink+&quot;.asp&quot;&quot; align=&quot;&quot;center&quot;&quot; width=100% height=100% ></IFrame>&quot;

Response.Write (str_IncLink)
%>

If anyone knows of any other ways of doing this perhaps not using VBScript, let me know.

Ta

 
actually I would recommend that also. I do the same thing for various situations that would be more then likely includes if not for the valid reasons why they can't be includes on my main development site.

You can make a iframe virtualy undetecable as a frame to the viewer so it is a good option.

____________________________________________________
The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-2924

onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top