打破“做同时”无限循环使用命令按钮 [英] Breaking a "Do While" Infinite Loop using a command button

查看:68
本文介绍了打破“做同时”无限循环使用命令按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是第二年的计算机工程专业的学生,​​我的VB6代码有问题。我刚开始学习VB6项目,我们必须创建一个显示骑士骑手灯序列的表格。显然,这意味着使用循环,我们的讲师告诉我们使用计时器来控制序列持续多长时间。我不想使用计时器((这不是因为懒惰,如果我使用计时器,我很久以前就已经完成了!!我只是想看看是否有另一种方法来做这个项目),我到处都读过,打破无限循环的唯一方法是Ctl + Alt + Del!我要问的是 - 是否有任何代码可以用来覆盖我的循环也可以用命令按钮链接(即当我在我的表单上按下''退出''按钮时,程序停止运行)。如果这不可能,用户可以输入一个停止程序的数字的方式也是一个很好的帮助。我正在研究这个模块是接口,所以用户兼容性是最重要的。也许有一个不同的循环我可以使用它提供更多的灵活性?


以下是我目前的代码大纲:


私有子cmdstart_click()

昏暗指数为整数


Do x< 50 (没有特别的原因为什么我选择50,我只想创建一个无限循环)


x = 0到7

DoEvents


下一页x


x = 6到0步-1


做事件


下一个x


循环




结束Sub

退出按钮代码


Private Sub Command1_Click()

卸载我

结束子


我没有在代码中发布''事件'',因为帖子guidlines建议你不应该发布所有代码。我需要在两天内完成,所以任何帮助都表示赞赏!在此先感谢,Anna。

Hello, I''m a 2nd year Computer Engineering student and I have a problem with my VB6 code. I''ve just started learning VB6 for a project in which we have to create a form which displays the knight-rider light sequence. Obviously, this means using a loop and our lecturer has told us to use timers to control how long the sequence lasts for. I don''t want to use timers ((this is not due to laziness, I would have been finished long ago had I used timers!! I just want to see if there is another way to do this project) , and I''ve read everywhere that the only way to break out of an infinite loop is Ctl+Alt+Del! What I am asking is - is there any code I could use to over-write the loop which I could also link with a command button (i.e. when I hit my ''exit'' button on my form, the program stops runnning). If this is not possible, a way in which the user could input a number which would stop the program would also be a great help. The module I''m studying this for is interfacing, so user-compatability is paramount. Perhaps there is a different loop I could use which offers more flexibility?

Here is an outline of my code so far:

Private Sub cmdstart_click()
Dim Index As Integer

Do While x < 50 (There''s no particular reason why I chose 50, I just wanted to create an infinite loop)

For x = 0 To 7

DoEvents

Next x

For x = 6 To 0 Step -1

Do Events

Next x

Loop




End Sub

Code for ''Exit'' Button

Private Sub Command1_Click()
Unload Me
End Sub

I haven''t posted the ''events'' in the code, as the posting guidlines advise that you shouldn''t post all of your code. I need to have this done in two days, so any help is appreciated! Thanks in advance, Anna.

推荐答案

您的代码没有任何意义。因为X不会超过50。

使用boolen Flag,如果标志为false则定时器控制然后运行循环如果为true然后停止。
Your code doesn?t make any sense. Because X will not go beyond 50.
use boolen Flag, timer control if the flag is false then run loop if it true then stop.


当然你'只需设置一个标志?


在项目顶部设置userexit为boolian


然后在你的循环中检查userexit = true然后退出循环


然后在命令按钮(用户输入)上设置userexit = true。



in ''理论''可行,试试吧:)
Surely you''d just set a flag?

at the top of your project set userexit as boolian

then in your loop check if userexit = true is so then exit the loop

then on the command button (user input) just set userexit = true.


in ''theory'' that would work, try it :)


大声笑,同样的想法,同时发布:)
lol, same idea, posted the same time :)


这篇关于打破“做同时”无限循环使用命令按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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