使用按钮终止VBS中的循环 [英] Terminating a loop in VBS with a button

查看:1086
本文介绍了使用按钮终止VBS中的循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西:

Stop = False
Do until stop = True
Objshell.sendkeys "Blah blah blah"
Wscript.sleep 100
Loop
Wscript.echo "Stop?"
Stop = True

我要尝试做的是使循环运行,但停止"?对话框打开,单击时将停止值设置为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?

推荐答案

为此,您必须使用InternetExplorer COM对象创建自定义对话框:

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

这篇关于使用按钮终止VBS中的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆