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!

VBscript & Server-side include 3

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
US
Hello all!

This is probably pretty simple but it escapes me. On an ASP page, I'm using VBScript to output a server-side include using the Response.Write method. Unfortunately nothing on the webpage comes out, not even an error message. So I think it's partially working, just not outputing the right stuff. Here's the code I have:

<%
Dim fso, f
Dim text
Dim text1
Dim text2
Dim myString
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fso_OpenTextFile(&quot;c:\inetpub\ 1)
text = f.ReadAll
If screenWidth = 1024 Then
If Len(text) > 5500 Then
text1 = Mid(text, 1, 5500)
text2 = Mid(text, 5500, Len(text))
Set f = fso.CreateTextFile(&quot;c:\inetpub\ f.Write (text1)
f.Close
Set f = fso.CreateTextFile(&quot;c:\inetpub\ f.Write (text2)
f.Close
Response.Write &quot;<!--#include file=&quot; & &quot;text1.txt&quot; & &quot;-->&quot;
Else
Response.Write &quot;<!--#include file=&quot; & &quot;filler.txt&quot; & &quot;-->&quot;
End If
Else
Response.Write&quot;<!--#include file=&quot; & &quot;filler.txt&quot; & &quot;-->&quot;
End If
%>


Can someone help me out real quick?

Thanks,
Jisoo22
 
If ... then
Response.Write &quot;<!--#include file=&quot; & &quot;text1.txt&quot; & &quot;-->&quot;
Else
Response.Write &quot;<!--#include file=&quot; & &quot;filler.txt&quot; & &quot;-->&quot;
End If
Else
Response.Write&quot;<!--#include file=&quot; & &quot;filler.txt&quot; & &quot;-->&quot;

This doesn't work.

Instead, do this:

If something = this then%>
<!--#include file=&quot;text1.txt&quot;-->
<%else%>
<!--#include file=&quot;filler.txt&quot;-->
<%end if%>

notice how you cannot have any kind of variables or anything inside the <!--#include declaration.

hope this helps
leo

 
Thanks for the help, now I have another small problem. When I put the includes in directly like you said, it worked the first time. But when I deleted that text files (except for filler.txt) and tried to test it again, it instantly tried looking for the text1.txt file even though it's supposed to make one first. Can anyone tell me why this happens?

Thanks,
Jisoo
 
hi,

the include files must exist, even if the logic you have will not use the include file. iis reads the entire page into memory first, including all the include files, then parses it. you could generate a blank file for the ones you don't need.

i have heard the asp.net fixes this problem, but i have not used it yet to confirm it.

this could also be a very dangerous problem if you have more than one person accessing the page at a time. one person could be reading the test1.txt file while another one is writting it. just a precaution.
 
U have to put three &quot; not just one &quot; in a string variable
Try this

If ... then
Response.Write &quot;<!--#include file=&quot;&quot;&quot;text1.txt&quot;&quot;&quot;-->&quot;
Else
Response.Write &quot;<!--#include file=&quot;&quot;&quot;filler.txt&quot;&quot;&quot;-->&quot;
End If
Else
Response.Write&quot;<!--#include file=&quot;&quot;&quot;filler.txt&quot;&quot;&quot;-->&quot;

If u want to include &quot; in an string variable u have to put three of &quot;

Let's say u have mystr=&quot;Include file=&quot;
and u want to put the file to include
mystr=mystr&&quot;&quot;&quot;file.txt&quot;&quot;&quot;

and u have mystr like Include file=&quot;file.txt&quot;
 
Ah I see about how the ASP page is read then. Could problems with multiple users be avoided using Session variables for text1 and text2? Someone suggested this to me, but I'm not quite sure how to implement this. Can someone show me how? I really appreciate this feedback, it's educating me immensely!

Thanks!
Jisoo22
 
when you use session variables, each user get's their own session, thus their own set of variables.

If you are implementing something where you need to track specific users, then the easiest way to track them would be to use session variables.

In order to use session variables, though, your user has to have their browser set up to accept session level cookies.

For more on these cookies, see faq333-863

to assign a session variable, use this syntax:
Session(&quot;somevar&quot;) = newValue

to access a session variable, use this syntax:
Response.write Session(&quot;somevar&quot;)

Session variables stay in memory until the session ends (by either calling Session.Abandon, or 20 minutes (the IIS default) )

I hope this helps
leo
 
It works! Woo hoo! Thanks a bunch guys =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top