Solved

VBScript Question

Posted on 2004-08-11
2
185 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you might need to configure routing based not only on destination IP address, but also on a combination of destination IP address (or hostname) and destination port number. I will describe a method how to accomplish this with free tools. …
Greetings, Experts! First let me state that this website is top notch. I thoroughly enjoy the community that is shared here; those seeking help and those willing to sacrifice their time to help. It is fantastic. I am writing this article at th…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

822 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