使用keydown中断无限循环? [英] interrupt infinite loops with keydown?

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

问题描述

你好,我是visual basic 2005的新手,我正在制作一些带有do循环功能的程序。


i我试图让我的prog退出无限循环时一键在键盘上按下,但我不知道如何编码。谁能帮我?我非常感激。

解决方案

试试这个链接: http://www.softlookup.com/tutorial/vb/ch08.asp#Heading3


< blockquote class =post_quotes>
你好,我是visual basic 2005的新手,我正在制作一些带有do循环功能的程序。


i我试图让我的当按下键盘上的键时,prog退出无限循环,但我不知道如何编码。谁能帮我?我非常感激。



一个简单的方法是创建一个全局变量。我做了几次,创建了一个名为UserWantsOut的全局布尔值。当然,您可能更喜欢其他名称。


在您的循环中,只要说该变量为True即可退出,或者通过 while / until 子句,或循环中的 If 测试。


在KeyDown或KeyPress事件中,如果满足条件(特定键或其他),则只需设置 UserWantsOut = True


请注意,如果您的版本中的内容仍然类似于VB6,您可能需要在循环中使用DoEvents以允许Windows去看看键盘。



一个简单的方法是创建一个全局变量。我做了几次,创建了一个名为UserWantsOut的全局布尔值。您可能更喜欢另一个名称,当然一个简单的方法是创建一个全局变量。我做了几次,创建了一个名为UserWantsOut的全局布尔值。当然,您可能更喜欢其他名称。


在循环中,只要说变量为True即可退出,或者通过while / until子句或If测试在循环中。


在KeyDown或KeyPress事件中,如果满足条件(特定键或其他),则只需设置UserWantsOut = True。


请注意,如果您的版本中的内容仍然类似于VB6,您可能需要在循环中使用DoEvents以允许Windows查看键盘。




这很好,但我想我忘了问如何在所述循环中正确执行keydown / keypress事件。我将如何设置doevents语句?


hello, i am new to visual basic 2005 and i am making a few programs with the do loop function.

i am trying to make my prog exit an infinite loop when a key on the keyboard is pressed, but i have no idea how to code this. can anyone help me? i''d be very appreciative.

解决方案

Try this link: http://www.softlookup.com/tutorial/vb/ch08.asp#Heading3


hello, i am new to visual basic 2005 and i am making a few programs with the do loop function.

i am trying to make my prog exit an infinite loop when a key on the keyboard is pressed, but i have no idea how to code this. can anyone help me? i''d be very appreciative.

One simple method is to create a global variable. I have done this a few times, creating a global boolean called UserWantsOut. You may prefer another name, of course.

In your loop, just say to drop out as soon as that variable is True, either by a while/until clause, or an If test inside the loop.

In the KeyDown or KeyPress event, if your conditions are met (specific key, or whatever) then simply set UserWantsOut = True.

Note that if things in your version still resemble VB6, you may nee to have a DoEvents inside your loop to allow Windows to go and look at the keyboard.


One simple method is to create a global variable. I have done this a few times, creating a global boolean called UserWantsOut. You may prefer another name, of courseOne simple method is to create a global variable. I have done this a few times, creating a global boolean called UserWantsOut. You may prefer another name, of course.

In your loop, just say to drop out as soon as that variable is True, either by a while/until clause, or an If test inside the loop.

In the KeyDown or KeyPress event, if your conditions are met (specific key, or whatever) then simply set UserWantsOut = True.

Note that if things in your version still resemble VB6, you may nee to have a DoEvents inside your loop to allow Windows to go and look at the keyboard.



this is good, but i guess i forgot to ask how to properly execute a keydown/keypress event within said loop. how would i set up the doevents statement?


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

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