PDA

Click to See Complete Forum and Search --> : Please look at my code!


compuGEEK
Mar 1st, 2001, 03:24 PM
I'm sure it's just a dumb mistake but I cannot see it (hmm..what does that make me then?!)

Anyway, I'm making a guestbook app that uses a text file, not a database.

My first form is called addentry.htm - It has 4 fields : Name, Email, URL and Comment. It then Posts to an ASP page called Submit. asp. This is where I am getting the following error:

Microsoft VBScript runtime (0x800A003E)
Input past end of file

Here is the code for Submit.ASP:



<%

Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim objFS, objFile, entries, textstream
Dim name, email,url, comment, signed

'read guestbook entries into textstream
Set objFS = Server.CreateObject ("Scripting.FileSystemObject")
set objFile = objFS.GetFile(server.mappath("entries.dat"))
set textstream = objFile.OpenAsTextStream(ForReading, -2)
entries = textstream.ReadAll
textstream.close

'read data entered into form
name = Request.Form("name")
email = Request.Form("email")
url = Request.Form("url")
comment = Request.Form("comment")
signed = FormatDateTime(Date, 1) & " " & Time

objFile.WriteLine("<font face=Verdana size=2>" & comment & "<p>")

'print name if entered
if Not(name = "") then objFile.WriteLine(name & "<br> ")

'print URL if entered
if Not(url = "") then objFile.WriteLine(url & "<Br> ")

'print email if entered
if Not(email = "") then objFile.WriteLine(email & "<Br> ")

'print date signed
objFile.WriteLine("- " & signed & "</font>")



objFile.WriteLine(entries)
'close file
objFile.close
response.redirect ("guestbook.asp")
%>



Is the error becuase I'm trying to add a date/time field?
Thanks,

CG

compuGEEK
Mar 2nd, 2001, 09:54 AM
Anybody? Please?

Jeh
Mar 2nd, 2001, 10:36 AM
Lo there,

Not sure if this will help or not, just looked like you were using a odd way of finding and opening the files etc.

following may work, havent tested it just edited the code u typed.


<%
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim objFS, objFile, entries, textstream
Dim name, email,url, comment, signed

'read guestbook entries into textstream
Set objFS = Server.CreateObject("Scripting.FileSystemObject")
objFile = Server.MapPath("entries.dat")
Set textstream = objFS.OpenTextFile(objFile, ForReading)
entries = textstream.ReadAll
textstream.Close
Set textstream = Nothing

'read data entered into form
name = Request.Form("name")
email = Request.Form("email")
url = Request.Form("url")
comment = Request.Form("comment")
signed = FormatDateTime(Date, 1) & " " & Time

Set textstream = objFS.CreateTextFile(objFile, 1)
textstream.WriteLine("<font face=Verdana size=2>" & comment & "<p>")

'print name if entered
if Not(name = "") then textstream.WriteLine(name & "<br> ")

'print URL if entered
if Not(url = "") then textstream.WriteLine(url & "<Br> ")

'print email if entered
if Not(email = "") then textstream.WriteLine(email & "<Br> ")

'print date signed
textstream.WriteLine("- " & signed & "</font>")
textstream.Write(entries)
textstream.Close
Set textstream = Nothing
Set objFS = Nothing

response.redirect ("guestbook.asp")
%>