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!

Loop

Status
Not open for further replies.

alcool9999

Technical User
Apr 1, 2008
3
GB
Hi

Code:
main()
Sub main()
Set FS = CreateObject("Scripting.FileSystemObject")
Set a = Fs.OpenTextFile("C:\Documents and Settings\Alex\desktop\create.txt",2,true)
a.write("hello")
a.close
End Sub
Set FS = CreateObject("Scripting.FileSystemObject")
if Fs.FileExists("C:\Documents and Settings\Alex\desktop\stop.txt") then
else
main()
End if

I need a sort of loop using a sub. It is supposed to kepp going back to the sub untiil the file stop.txt appears but it only goes through the sub twice and i don't know why? by the way the bit inside main() is just so i know that its still going.

Thanks
 
Your loops don't seem to have any connection here. Anyway here is a sample that will open the first file, try to write hello 1000 times. After 100 times it will create the second text file and exit the loop.


Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set a = objFSO.OpenTextFile("C:\Documents and Settings\Alex\desktop\create.txt",2,true)

Do Until objFSO.FileExists("C:\Documents and Settings\Alex\desktop\stop.txt")

  For x = 1 to 1000
      a.write("hello")
      If x = 100 Then
           objFSO.CreateTextFile("C:\Documents and Settings\Alex\desktop\stop.txt")
      End If
      a.close
  Next
Loop

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top