单击屏幕上的“取消"按钮时如何退出Do循环. [英] How exit Do loop when clicking on a 'Cancel' button on the Screen.

查看:79
本文介绍了单击屏幕上的“取消"按钮时如何退出Do循环.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个问题.

我写了一个小程序来编程RFID卡.
读卡器的软件中有一个功能正在检查读卡器上是否有卡.
因此,当我单击屏幕编程卡上的按钮时,我进入了Do循环功能以检查读取器上是否有卡,如果有卡,则转到下一个编程功能.当没有卡的时候,我就一直处于循环中.
这是应该的,但是需要在屏幕上实现一些按钮,因此,当单击取消"按钮时,循环将停止.

因此,当用户不想对卡进行编程时,只需单击取消"按钮即可退出do循环.

做这样的事情的最好和正确的方法是什么.

坦克.


br.

Didier

Hello,

I have a question .

I have written a small programm to programm RFID Cards.
There is a funtion in the software of the cardreader that is checking if there is a card on the reader.
So when i click the button on the screen programm card , i put in a Do loop function to check if there is a card on the reader , if there is a card i go to the next programming function. When there is no card Yet i keep in the loop.
This is working like it should be but is need to implement some button on the screen so when clicking on the button ''Cancel'' that the loop is stopped.

So when the user don''t want to program the card anyway so that he can escape from the do loop by clicking on the ''Cancel'' button.

What is the best and correct way to do something like this.

Tanks.


br.

Didier

推荐答案

BackgroundWorker上运行循环应使您更容易处理这种情况.
请参见此处 [
Running your loop on a BackgroundWorker should make it easier for you to handle this situation.
See here[^].


尝试以下简单代码:

Try this simple code:

Public Class Form1
    Dim FlagCancel As Boolean
    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
        FlagCancel = False
        Do While FlagCancel = False
            My.Application.DoEvents()
        Loop
    End Sub
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        FlagCancel = True
    End Sub
End Class


这篇关于单击屏幕上的“取消"按钮时如何退出Do循环.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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