ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 6th, 2003, 04:10 PM
anoyes anoyes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: MA, USA
Posts: 38 anoyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Including .txt file in If-Then Statement

How would I go about including a .txt file in an If-Then statement? Basically what I want is to have a certain file included depending on what the value of Request.QueryString("type") is equal to. Any ideas?

Reply With Quote
  #2  
Old September 6th, 2003, 05:55 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,982 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 18 h 42 m 27 sec
Reputation Power: 814
In asp include files are combined with the main page before any asp code is executed, so you can't conditionally include a file. You can conditionally execute the code in an included file though

Code:
<% If someCondition Then %>
  <!--#include file="include1.inc"-->
<% Else %>
  <!--#include file="include2.inc"-->
<% End If %>


In this example, both include1.inc and include2.inc are in the page, but only the code in the if block that's true will be executed.

I don't know about asp.NET

Reply With Quote
  #3  
Old September 6th, 2003, 06:03 PM
anoyes anoyes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: MA, USA
Posts: 38 anoyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Maybe this'll be easier. What I want to do is display a certain table depending on the Request.QueryString("type") value. How would I go about displaying certain tables based on the conditions?

Reply With Quote
  #4  
Old September 6th, 2003, 08:00 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
generally you write a function to print the tables
Code:
 if a then
 printTable()
else
 printTable2()
end if


but there's a really a thousand different ways, this should be the easiest.

Reply With Quote
  #5  
Old September 6th, 2003, 08:37 PM
anoyes anoyes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: MA, USA
Posts: 38 anoyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Ok, here's the code (or part of the code) that I have:

<%
If Request.QueryString("type")="" Then
PrintTable (
<table border="0" cellpadding="0" cellspacing="0" width="797" id="AutoNumber1" height="374">
blah blah blah, etc., etc. </table>)
End If
%>

Then, when I try to view the page, I get the following error:Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/projects/completed/default.asp, line 13, column 12
PrintTable (
-----------^

Reply With Quote
  #6  
Old September 6th, 2003, 09:51 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
I don't know what you're doing, this is waht i'd do
Code:
Function PrintTable()
   dim strBody
   strBody = "table border=""0"" cellpadding=""0"" cellspacing=""0"" width=""797"" id=""AutoNumber1"" height=""374""> blah blah blah, etc., etc. </table>"
   PrintTable=strBody
end Function


then in code
Code:
if  Request.QueryString("type")="" then
   response.write PrintTable()
end if


***note, i didn't test any of this**

Reply With Quote
  #7  
Old September 7th, 2003, 06:44 PM
anoyes anoyes is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: MA, USA
Posts: 38 anoyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hmmm, it works but makes the code "ugly." lol. Hard for editing cause it's all one one line (if i try to break it up I get an "unterminated string" error). Is there any way to show the contents of a .txt file conditionally, rather than including it? Or is that essentially the same thing?

Reply With Quote
  #8  
Old September 7th, 2003, 06:53 PM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
Quote:
works but makes the code "ugly."

Holy Crap.......??? uhhhh... i don't know where to begin with that statement....

one of the key aspects of programming is modularization. You need to break things up, hence the origin of object oriented programming. when you break things off into functions you don't have to worry about variable names and other things overwriting or interfering with data in the other parts of the program as well as keep less in your head if you know "that part" of a program works, you just use it and don't have to worry about how it works. It's really quite key and I pity the programmer that looks down upon this method since you'll only make your life more difficult....

as for harder to edit? I assume you mean the string being one line, do you know how to concatenate strings and everything?

The "" prints out a " to the screen, yea, it's ugly, i do it for shorthand, you can use & quot ; except without the spaces to print out a quote instead of "". just do this
Code:
 
strBody = "<table border=""0"" cellpadding=""0""" & _
          "cellspacing=""0"" width=""797"" " & _
        "id=""AutoNumber1"" height=""374"">" & _
           blah blah blah, etc., etc. </table>"
   PrintTable=strBody


you can continue onto the next line by doing a & _ at the end of the string. You can also just on the next line say
strBody = strBody & "blah blah blah" and it will concatenate onto the end.

as for your second question, you're going to need to pick a method and go with it, do you want to print a table or open a txt file? you can use FSO and print out the file to screen, and just change the filename to open in the if statement. Table print method shown above.

Last edited by unatratnag : September 7th, 2003 at 06:57 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Including .txt file in If-Then Statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT