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

BEGINNER: TEXT STREAM DON'T WORK - HELP!!!!

Status
Not open for further replies.

LoserAndFailure

Programmer
Jan 27, 2005
4
US
I hope you guys can help me. I am doing an example out of the book "Beginning Active Server Pages 3.0", Chapter 10. This is an example about text streams. I copied this code WORD FOR WORD FROM THE BOOK and it DOESN'T WORK! The only way it will work is if I use THE AUTHOR'S code, which I downloaded from the Wrox website, which is IDENTICAL to mine! I am so upset! I want you guys to take a look at my code and compare it to the author's, and tell me if you can see any difference, and why mine isn't working. Theirs works BEAUTIFULLY and mine doesn't work AT ALL! I'm honestly beginning to believe it's because of who I am and has nothing to do with the code. Here are the codes below:

AUTHOR'S:
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim strPathInfo, strPhysicalPath
strPathInfo = Request.QueryString("FileName")
strPhysicalPath = Server.MapPath(strPathInfo)

Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPhysicalPath)
%>

<HTML>
<HEAD>
<TITLE><%= objFile.Name %> Source Code</TITLE>
</HEAD>
<BODY>
Source code for <%= objFile.Name %><HR><P>
<FONT FACE=Courier SIZE=2>

<%
Dim objFileTextStream
Set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)

Dim strLine
Do While objFileTextStream.AtEndOfStream <> True
strLine = Server.HTMLEncode(objFileTextStream.ReadLine)
strLine = Replace (strLine, Chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;")
Response.Write strLine
Response.Write "<BR>" + vbCrLf
Loop
objFileTextStream.Close
%>

</FONT>
<BR>
<BR>
<HR>
<A HREF="<%= strPathInfo %>">Return to Displayed File</A>
</BODY>
</HTML>

MINE:
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim strPathInfo, strPhysicalPath
strPathInfo = Request.QueryString("FileName")
strPhysicalPath = Server.MapPath(strPathInfo)

Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPhysicalPath)
%>
<html>
<head>
<title><%= objFile.Name %> Source Code</title>
</head>
<body>
Source code for <%= objFile.Name %><hr><p>
<font face="Courier" size="2">
<%
Dim objFileTextStream
Set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)

Dim strLine
Do While objFileTextStream.AtEndOfStream <> True
strLine = Sever.HTMLEncode(objFileTextStream.ReadLine)
strLine = Replace (strLine, Chr(9), "&nbsp;&nbsp;&nbsp;&nbsp;")
Response.Write strLine
Response.Write "<br>" + vbCrLf
Loop
objFileTextStream.Close
%>
</font>
<br><br>
<hr>
<a href="<%= strPathInfo %>">Return to Displayed File</a>
</body>
</html>

I so hope you guys can help me, and I so hope this is a code problem and not an identity problem. Anyways your help will be greatly appreciated. Sorry for the length.

Sincerely,
LoserAndFailure
 
as Tony pointed out...correct that typo and post back if you have more questions or get any errors...to be more specific, post the the actual error that you get...

-DNG
 
Thank you Chris and Tony!

Actually I didn't get any errors, just a blank page. It works now! That'll teach me not to rely solely on Notepad anymore! Hey, do you guys know of any good ASP editors out there that catch typos like that? I have Microsoft's FrontPage and Visual Studio, but I don't think they have an ASP editor in them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top