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

NEWBIE: Getting Input past end of file when I run script

Status
Not open for further replies.

dexter105

IS-IT--Management
Sep 24, 2009
2
US
Hello all, first this is an awesome forum.
I am trying to read a file and take the first 10 letters from the left and the last 7 from the right...put them together in a new file.

I have butchered some code I found on the internet and this is what I have so far but when I run it I get...
Error: "Input past end of file"
Code: 800A00E3
System: Space to store the file waiting to be printed is not available on server.

Here is the code:
Dim i
Dim filesys, text, readfile, contents

set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\logs\WORKFILEA.txt", 1, false)
do
contents = left((readfile.ReadLine), 10) & " ---> " & Right((readfile.ReadLine), 7)
WScript.Echo "The line contains the following text - '" & contents & "'."

i = contents
Loop While i <>
 
Do you mean the left 10 and right 7 of each line or of the entire file?

The Entire File:
Perhaps a better method would be to read the entire file contents using objFSO.ReadAll and then extracting the data you need. Be aware, however, that this method could yield odd behavior or crash if a file is too big and cannot be stored within a string type.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile("c:\logs\WORKFILEA.txt", 1, false)

strContent = objFile.ReadAll
strNewContent = left(strContent, 10) & " ---> " & right(strContent, 7)
wscript.echo "The line contains the following text - '" & strNewContent & "'."

Each Line:
You are very close to having working code. Conditionalize your loop by subjecting it to the .AtEndOfStream property.

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile("c:\logs\WORKFILEA.txt", 1, false)

do [b]while NOT objFile.AtEndOfStream[/b]
   strLine = objFile.ReadLine
   strNewContent = left(strLine, 10) & " ---> " & right(strLine, 7)
   wscript.echo "The line contains the following text - '" & strNewContent & "'."
loop

-Geates

-Geates
 
I meant the left 10 and right 7 of each line. The file I am reading will be a log file and I need the beginning 10 and the last 7 of each line. You are right on the money!!! Thanks so much for you help.
 
its funny i used to think a runtime would be thrown if the string you were performing a Left(xxx, 10) on has a length less than 10...just checked and it doesnt....even so you might want to consider
If Len(strLine) > 10 Then
'''do your stuff
Else
'hmm take some corrective action
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top