Solved

VBScript Question

Posted on 2004-08-11
2
183 Views
Last Modified: 2010-03-18
Someone please tell me why this script never exits the Loop PLEASE!

On Error Resume Next

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim fso, f, s

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading, True)
Do While NOT f.AtEndOfStream
   s = f.readline
   wscript.Echo s
   f.Close
Loop

0
Comment
Question by:Packerland
2 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 11774228
try:
while NOT f.AtEndOfStream
   s = f.readline
   wscript.Echo s
   f.Close
Loop
0
 
LVL 14

Accepted Solution

by:
JohnK813 earned 500 total points
ID: 11774250
Try moving your f.Close outside the loop (as in, after it).  f.Close closes your stream, so that's probably why you're never getting an AtEndOfStream signal.

Do While NOT f.AtEndOfStream
   s = f.readline
   wscript.Echo s
Loop
f.Close
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Resolve DNS query failed errors for Exchange
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now