问题
I have something like this:
Stop = False
Do until stop = True
Objshell.sendkeys "Blah blah blah"
Wscript.sleep 100
Loop
Wscript.echo "Stop?"
Stop = True
What I'm trying to do is make it so that the loop runs, but the "Stop?" dialogue box is open, and when it is clicked the stop value is set to true and the loop should terminate. So what I'm really asking is if I can make the code outside of the loop run at the same time as the code inside of the loop. Can anyone help?
回答1:
You'll have to make a custom dialog with the InternetExplorer COM object for this:
Set ie = CreateObject("InternetExplorer.Application")
ie.Offline = True
ie.Navigate "about:blank"
Do While ie.Busy : WScript.Sleep 100 : Loop
ie.document.Title = "Exit loop?"
ie.document.body.innerHTML = "<button name='exit' " _
& "onClick=document.all('continue').value='no'>Exit</button>" _
& "<input name='continue' type='hidden' value='yes'>"
ie.Height = 200
ie.Width = 425
ie.MenuBar = False
ie.StatusBar = False
ie.AddressBar = False
ie.Toolbar = False
ie.Visible = True
Do Until ie.document.all("continue").Value = "no"
' do stuff
WScript.Sleep 100
Loop
ie.Quit
来源:https://stackoverflow.com/questions/12597226/terminating-a-loop-in-vbs-with-a-button