IMPORTANT ANNOUNCEMENT

These forums were permanently set to read-only mode on July 20, 2022. From that day onwards, no new posting or comment is allowed on the site, but the historical content remains intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#18999 - 11/24/05 12:49 PM Need help with my script
dertown Offline
Member

Registered: 11/15/05
Posts: 31
I am trying to use this script to filter out the last half of the file. However it has to be done dynamicly. so i can not use a fixedset of lines.

Quote:

Dim file, strTest, stream

Set File = CreateObject("Scripting.FileSystemObject")

Set stream = file.OpenTextFile("FR21A1.txt")

strTest = stream.ReadLine
stream.WriteLine strTest

Do While strTest <>("LONDONDAY FOR- 600 HARVEYS")
strTest = stream.ReadLine
stream.WriteLine strTest

Loop

stream.Close
file.Close
The error I get is file not found. what am i doing wrong?

Thank you

Top
#19000 - 11/24/05 02:04 PM Re: Need help with my script
dertown Offline
Member

Registered: 11/15/05
Posts: 31
i have updated the code. here it is
Quote:

Dim file, newFile, strTest, stream, newText, strNew

Set file = CreateObject("Scripting.FileSystemObject")

Set stream = file.OpenTextFile(PW_GetJobFilename)
Set stream = file.CreateTextFile(PW_GetJobFilename)

strTest = stream.ReadLine
stream.Write strNew

Do While strTest <> LONDONDAY FOR- 600 HARVEYS")
strTest = stream.ReadLine
stream.Write strNew

Loop

stream.Close
I am getting and input error. File beyond limit

Top
#19001 - 11/24/05 04:53 PM Re: Need help with my script
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
Here' a corrected code:

--------------------
Dim file, newFile, stream, strNew

Set file = CreateObject("Scripting.FileSystemObject")

Set stream = file.OpenTextFile("C:\test.txt")
Set newFile = file.CreateTextFile("C:\filtered.txt")

Do While strNew <> "LONDONDAY FOR- 600 HARVEYS"
strNew = stream.ReadLine
newFile.WriteLine strNew
Loop

stream.Close
--------------------

Now, there was a critical error in your code. First of all, you first set the variable "stream" to open a text file, and then you set it to create a text file. When calling CreateTextFile, you override the previous OpenTextFile command, and therefore your file is never opened for reading. So I used two variables to fix this problem.

Also, these two lines:

strTest = stream.ReadLine
stream.Write strNew

They are not needed before the loop. They are already called in the "Do While" loop, you do not need to add them before your loop.

Try out my code, and see if it works. You can replace "C:\test.txt" by "PW_GetJobFilename", and set the path of the filtered text file to suit your needs. Do not use PW_GetJobFilename with CreateTextFile however.

Hope that solved your problem.

Regards,
Rapha

Top
#19002 - 11/29/05 10:16 AM Re: Need help with my script
dertown Offline
Member

Registered: 11/15/05
Posts: 31
Thank you for help that helped a lot. I have recieved another error though and that is "input past end of file"

How can i fix that. the data information is in ascii emulation so it should read it as a text file.

Top
#19003 - 11/30/05 09:10 AM Re: Need help with my script
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4956
Loc: Objectif Lune Montreal
The client reported this as an issue via the web, and I was able to solve his problem by correcting the errors in his code. Everything is working fine now, so this issue is now closed.

Rapha

Top