Terminating a loop in VBS with a button

时光总嘲笑我的痴心妄想 提交于 2020-01-05 07:26:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!