Can I use #include within an If Then statement?

This is a discussion on "Can I use #include within an If Then statement?" within the Classic ASP section. This forum, and the thread "Can I use #include within an If Then statement? are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jun 12th, 2006, 14:48
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Can I use #include within an If Then statement?

If so, how do I do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 12th, 2006, 14:53
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: Can I use #include within an If Then statement?

Nevermind - I figured it out...

Code: Select all
<%
(code)
(code)
(code)
If var = "value" Then
%>
<!-- #include file='file.ext' -->
<%
Else
   (other code)
End If
%>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 16th, 2006, 22:14
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 245
Thanks: 6
Thanked 0 Times in 0 Posts
Re: Can I use #include within an If Then statement?

AAAARGH! The above does not actually work!

The #include includes the file regardless of how the If statement evaluates! Grrr...

Code: Select all
 
<%
If this = "that" Then
%>
<!-- #include file='file1.ext' -->
<%
Else
%>
<!-- #include file='file2.ext' -->
<%
End If
%>
includes both file1 and file2!!!

I know I can get around this by simply putting the actual contents of the included files within the If statement, but is there another way to make the above work?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 28th, 2006, 12:05
New Member
Join Date: Jun 2006
Location: Norway
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Can I use #include within an If Then statement?

Yes, that is possible, but the source will be

<%
If this = "that" Then
%>
<% 'File 1 %>
some text or any functions
<%
Else
%>
<% 'File 2 %>
some text or any functions
<%
End If
%>

as you see, the IF statement will still be there, but both files will be included
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 28th, 2006, 12:08
New Member
Join Date: Jun 2006
Location: Norway
Age: 19
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Can I use #include within an If Then statement?

ths is how i included files by specific variables earlier, but now in using Function() instead, by already including the file at the start of the ASP source
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 30th, 2006, 18:29
Junior Member
Join Date: Jul 2006
Location: Manchester
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Can I use #include within an If Then statement?

You have two options to dynamically "include content".
1) use the execute method wich will run the ASP page in much the same way as the include method.....
if x = y then
execute "myfile.asp"
else
execute "myfile2.asp"
end if

or 2) the less pleasant way is to use FSO to read the contents of the file then write it out to the client. this is no good if the file contains serverside code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
use, include, within, then, statement

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP If Statement... mcdanielnc89 PHP Forum 16 Dec 9th, 2007 17:44
Include() Statement Is Getting Hacked peterwilby PHP Forum 1 Apr 26th, 2007 03:03
If..Else statement help IanW PHP Forum 3 Oct 6th, 2006 13:40
Help with If Statement. JohnMitch Classic ASP 2 Jan 5th, 2005 01:05
With Statement Trebz Classic ASP 2 Feb 2nd, 2004 14:56


All times are GMT. The time now is 04:11.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42