Failure in searching a text file

Results 1 to 2 of 2

Thread: Failure in searching a text file

  1. #1
    Join Date
    Dec 1969

    Default Failure in searching a text file

    &#060;%<BR> Dim strdate, strcontents, bolfound, strdatenumber<BR> Const Forreading = 1<BR> Dim objOpenFile, objFSO, strPath<BR> strPath = Server.MapPath("events.txt")<BR> Set objFSO = _<BR> Server.CreateObject("Scripting.FileSystemObject")< BR> strdatenumber = 1<BR> Set objOpenFile = _<BR> objFSO.OpenTextFile(strPath, forreading)<BR> strdate = objopenfile.readline<BR> strdate = dateadd("d",strdatenumber,strdate)<BR> do while not bolfound = true <BR> strcontents = objopenfile.readline<BR> if Instr(1,strcontents,strdate,1) then <BR> bolfound = true<BR> end if<BR> loop<BR> if bolfound = true then<BR> Response.Write("&#060;B&#062;" & "strcontents" & "&#060;/b&#062;&#060;P&#062;")<BR> do while strcontents is not ""<BR> strcontents = objopenfile.readline &#060;&#060;&#060;ERROR HERE&#062;&#062;&#062;<BR> Response.Write(strcontents) & Response.Write("<BR>")<BR> loop<BR> end if<BR> objOpenFile.Close<BR> Set objOpenFile = Nothing<BR> Set objFSO = Nothing<BR>%&#062;<BR><BR>The above code is meant to search through the specified text file until it finds the date worked out at the start. Once it has found that date, it prints out the text file line by line until it reachs a blank line. The error occurs on line 25, marked in the code above, it is a server.createobject failed error. The text file is set up correctly and permissions are correct, can anyone help me with this???<BR><BR>Cheers,<BR><BR>Robert Smith<BR>BSZ Marketing

  2. #2
    Join Date
    Dec 1969

    Default Maybe yes, maybe no...

    I&#039m *guessing* that you are off by one line on which one has the error. Take a look at the line following the one you said the error is on:<BR><BR> &nbsp; &nbsp; Response.Write(strcontents) & Response.Write("&LT;BR&#062;")<BR><BR>HUH???? Do you understand what that is trying to do? Because you used the string concatenation operator (&), it is trying to conver the SECOND Response.Write on that line into a string! And of course it can&#039t do that. Try changing that line to<BR><BR> &nbsp; &nbsp; Response.Write strcontents & "&LT;BR&#062;" & vbNewLine<BR><BR>and see if it doesn&#039t work better.<BR><BR>If I&#039m wrong, post again.<BR><BR><BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts