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

Error Message Meaning and ts.endofstream PROB 1

Status
Not open for further replies.

UnfitElf

Programmer
Dec 3, 2002
24
NZ
Dose any body know what this error means??

Microsoft VBScript runtime error '800a0036'

Bad file mode

/clannzb/data.asp, line 37

Thanks for any help

And

If you look at the code bellow when i type text in to the text file TEMP_N_C.txt but i have a Carrage return in it it only reads the bottom line eg.

TEMP_N_C.txt:
Dan
2/12/2002
Welcom this is the text of the file it works fine untill i do this
now it doesn't work it only writes out to the form the text after the carrage return

End of file

in this eg. it would only write out: "after the carrage return" bit, How do get it to write out the WHOLE thing???


<%
set fs=server.createobject(&quot;scripting.filesystemobject&quot;)
set ts=fs.opentextfile (server.mappath (&quot;db/TEMP_ID.txt&quot;),1,true)
do until ts.atendofstream
ID = ts.readline
Loop

if ID = &quot;1&quot; then

set fs=server.createobject(&quot;scripting.filesystemobject&quot;)
set ts=fs.opentextfile (server.mappath (&quot;db/TEMP_N_C.txt&quot;),1,true)
NoP = ts.readline
ignorLine = ts.readline
do until ts.atendofstream
CoP = ts.readline
Loop

Else
NoP = &quot;&quot;
CoP = &quot;&quot;
End if

set fs=server.createobject(&quot;scripting.filesystemobject&quot;)
set ts=fs.opentextfile (server.mappath (&quot;db/TEMP_SUB1_SUB2.txt&quot;),2,true)
ts.writeline &quot;&quot;
%>
Guest Book:<br>
<br>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;data.asp&quot;>
<p>Your name:
<input name=&quot;namePerson&quot; type=&quot;text&quot; value=<% response.write NoP%>>
</p>
<p> The date is:
<input type=&quot;text&quot; name=&quot;date&quot; value=&quot;<%=date%>&quot;>
</p>
<p>Comments:</p>
<p>
<textarea name=&quot;comments&quot; cols=&quot;45&quot; rows=&quot;5&quot;><% response.write CoP%></textarea>
</p>
<p>
<input type=&quot;submit&quot; name=&quot;BUTTON&quot; value=&quot;Preview&quot;>
<input type=&quot;submit&quot; name=&quot;BUTTON&quot; value=&quot;Submit&quot;>
<input type=&quot;reset&quot; name=&quot;BUTTON&quot; value=&quot;Reset&quot;>
</p>
</form>
 
Ok, first, you should close and dereference your stream between the differant reads, you also don't need to re-instantiate the FileSystemObject each time you want to open a file. So for the first part that gives us:
Code:
<% 
set fs=server.createobject(&quot;scripting.filesystemobject&quot;)
set ts=fs.opentextfile (server.mappath (&quot;db/TEMP_ID.txt&quot;),1,true)
'After this loop the value of ID will be the last line in the file
Code:
do until ts.atendofstream
   ID = ts.readline
Loop

ts.Close
'Close TextStream
Code:
Set ts = Nothing
'Dereference object
Code:
if ID = &quot;1&quot; then

set ts=fs.opentextfile (server.mappath (&quot;db/TEMP_N_C.txt&quot;),1,true)
NoP = ts.readline
'Read First Line
Code:
ignorLine = ts.readline   '
'Read Second Line
Code:
'The following loop insures that CoP is the last line of the file
Code:
do until ts.atendofstream
CoP = ts.readline
Loop

ts.Close
'Close TextStream
Code:
Set ts = Nothing
'Dereference object
Code:

Your second file has to be a minimum of 3 lines.
The file will read line 1 (Dan) into the NoP variable.
It will read line 2 (date) into the ignore variable,
it will read line 3 (text) into the CoP variable,
it will read line 3(text) into the CoP variable (overwriting previous contents)

If you want everything from the 3rd line on in the CoP variable then change the loop to this:
Code:
'The following loop assigns rest of file to CoP
Code:
CoP = &quot;&quot;
do until ts.atendofstream
   CoP = CoP & ts.readline
Loop


Hope that fixes it for you,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top