?
Solved

DOevents question

Posted on 1998-09-16
1
Medium Priority
?
210 Views
Last Modified: 2010-04-30
I am writing a serial interface program and use the loop to poll the data from buffer. In the loop there is a Doevents to return the control to the OS. If during the Doevents period the user press stop button, can I get out of the loop that I was running and do something else?
0
Comment
Question by:Overflow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
trkcorp earned 200 total points
ID: 1435339
Yes. That is the purpose of DoEvents, to allow a break in a hard loop. In order to make this work though you will have to be able to detect that the button was clicked from within your hard loop and then take appropriate action.  For example:

Option Explicit
Dim bStop as Boolean

Private Sub cmdStop_Click()
bStop = True
End Sub

Sub HardLoop()
Do
  DoEvents
  If bStop then Exit Do 'or maybe Exit Sub?
Loop
End Sub

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question