Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I read a file line by line in VB Script?
    text
    copied!<p>I have the following to read a file line by line:</p> <pre><code>wscript.echo "BEGIN" filePath = WScript.Arguments(0) filePath = "C:\Temp\vblist.txt" Set ObjFso = CreateObject("Scripting.FileSystemObject") Set ObjFile = ObjFso.OpenTextFile(filePath) StrData = ObjFile.ReadLine wscript.echo "END OF FIRST PART" Do Until StrData = EOF(ObjFile.ReadLine) wscript.echo StrData StrData = ObjFile.ReadLine Loop wscript.echo "END" </code></pre> <p>The <code>EOF()</code> function doesn't seem to work:</p> <pre><code>C:\Users\EGr\Documents\Scripts\VB&gt;cscript testloop.vbs ArgVal Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. BEGIN END OF FIRST PART C:\Users\EGr\Documents\Scripts\VB\testloop.vbs(11, 1) Microsoft VBScript runti me error: Type mismatch: 'EOF' </code></pre> <p>I haven't programmed in VB before, but I'm trying to figure out loops so that I can modify a VB script I've been handed. I want to read a file line by line, and do something with each line. If I change the Do Until loop to <code>Do Until StrData = EOF</code>, it works but throws an error when it gets to the end of the file:</p> <pre><code>C:\Users\EGr\Documents\Scripts\VB&gt;cscript testloop.vbs ThisRANDOMValue Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. BEGIN 1 END OF FIRST PART host1 host2 host3 C:\Users\EGr\Documents\Scripts\VB\testloop.vbs(13, 2) Microsoft VBScript runti me error: Input past end of file </code></pre> <p>I feel like there is probably an easy solution, but I haven't been able to find it. I've tried a few other solutions I've found online, but haven't got as close as the above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload