Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBscript error input past end of file

Tags:

vbscript

I have 3 scripts wherein they all must be run in the right order repeatedly.

  1. 1st script - performs a process on a list of PCs (listed on a textfile input) depending if they are online/offline. It outputs a list of the PCs which were online and another list of the offline ones
  2. 2nd script - gets the PC difference from the original list and the output of the 1st script to know which machines have run the process from the 1st script
  3. 3rd script - using the differences, updates the input list

The script below is the 3rd script. Whenever I run it, it ends with an error "input past end of file". I've tried several modifications and it always ends that way.

My idea for the 3rd script is that the Differences.txt output from the 2nd file are the ones that still need to run the process form the first script, so I simply delete the original input file and rename this one into the new output file. However, I have to also keep track of the ones that were already done with the process so I have to list/append them to another text file.

Thanks in advance for any help.

Option Explicit
Dim objFso
Dim Fso
Dim firstfile,secondfile,file,fileText

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("Machines.ini") Then objFSO.DeleteFile("Machines.ini")

Set Fso = WScript.CreateObject("Scripting.FileSystemObject")
Fso.MoveFile "Differences.txt", "Machines.ini"

firstfile="Notified.txt"
secondfile="Notified-all.txt"

Set fso=CreateObject("Scripting.FileSystemObject")
Set file=fso.OpenTextFile(firstfile)
fileText = fileText & file.ReadAll() & vbCrLf
file.Close

Set file=fso.OpenTextFile(secondfile)
fileText=filetext & file.ReadAll()
file.Close

set file=fso.CreateTextFile(secondfile,true)
file.Write fileText
file.close
like image 315
Programmer Avatar asked Sep 25 '14 01:09

Programmer


People also ask

How do I fix input past end of file?

To correct this errorUse the EOF function immediately before the Input statement to detect the end of the file. If the file is opened for binary access, use Seek and Loc .

How do I fix Runtime Error 62?

Follow the below troubleshooting steps to address this error: Delete all files in the folder located in C:\Program Files\Juris2\bin\JRQ or C:\Program Files (x86)\Juris\bin\JRQ. Confirm user has full read write control over C:\Program Files\Juris2\bin or C:\Program Files (x86)\Juris\bin. Preview or print the report.


1 Answers

You get that error when you call ReadAll on an empty file. Check the AtEndOfStream property and read the content only if it's false:

If Not file.AtEndOfStream Then fileText = fileText & file.ReadAll
like image 105
Ansgar Wiechers Avatar answered Oct 06 '22 01:10

Ansgar Wiechers