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

How Can I add an INCLUDE FILE within an IF Statment

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I have the following snippet that searches the http_referer screen and if it has certain values (i.e., called from within the application), then don't update a hit counter.

However, I keep getting a syntax error. It happens at my else statement where I'm trying to include the counter file. If I take the include out of the If condition, it works fine. I also get an error if I say ..& <!-- #include --> ....


<%
dim previous
previous = Request.ServerVariables(&quot;HTTP_REFERER&quot;)
'previous now contains the value of the previous script
response.write &quot;Value of var = &quot; & previous
if InStr(1, previous,&quot;classifieds&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;about&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;directory&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;about&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;advertise&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
else
response.write &quot; You are visitor number &quot; & #INCLUDE FILE=&quot;counter.asp&quot; & &quot;to this site.&quot;
end if

%>


Any help is appreciated.

Thanks,
scripter73
Change Your Thinking, Change Your Life.
 
Includes are processed when the ASP is first read, compiled and cached. Putting it in an IF will not keep it from being included. If you insist then try
& %>
<!-- #include FILE=&quot;counter.asp&quot; -->
<% &



Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
hmm, haven't tried it,..have had no use for such an action, however, you probably could write the text to the client if the page were buffered...it may work...don't know...try it...

<%
Dim i
i = 1

If i = 1 Then
Response.write(&quot;<!-- #include file=&quot;&quot;counter.asp&quot;&quot; -->&quot;)
End If
%>

If it doesn't work writing it out like that, then try seperating the statement like the following...

Response.write(&quot;<&quot;)
Response.write(&quot;!-- #&quot;)
Response.write(&quot;include FILE=&quot;)
Response.write(&quot;&quot;&quot;counter.asp&quot;&quot;&quot;)
Response.write(&quot; --&quot;)
Response.write(&quot;>&quot;)

If it still doesn't work. I guess you can't...doesn't hurt to try though. It has been my understanding that the include files will be processed before anything else...however, the server has to go through the server side code first between the <% and %> delimiters, and when writing server include files, you write it in html format...so it may just work this way...but perhaps better odds if you buffer it so it processes the entire page before sending to the client.

Just some thoughts. I'd be interested to hear if it works...can you let us know?

-Ovatvvon :-Q
 
The codes within an if statement so it wont be executed . fine.
The code problem is that the include needs to be outside the asp tags.

<%
dim previous
previous = Request.ServerVariables(&quot;HTTP_REFERER&quot;)
'previous now contains the value of the previous script
response.write &quot;Value of var = &quot; & previous
if InStr(1, previous,&quot;classifieds&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;about&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;directory&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;about&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
elseif InStr(1, previous,&quot;advertise&quot; , VBTextCompare) then
response.write &quot; In string, therefore don't count&quot; & &quot;<br>&quot;
else
%>
You are visitor number
<!--#include file=&quot;counter.asp&quot; -->
to this site.
<%
end if

%>
 
Thanks everybody for the attempts, I tried both, but I think the latter worked out for me.

Thanks again for your suggestions.

scripter73


Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top