|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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?
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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?
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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 ( -----------^ |
|
#6
|
|||
|
|||
|
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** |
|
#7
|
|||
|
|||
|
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?
|
|
#8
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Including .txt file in If-Then Statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|