Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Issues with DoEvents command

On Aug 28, 2:13 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
What exactly are you trying to accomplish? I understand that you want code
execution to continue while the user is working in the sheet but that is a
VERY hit and miss proposition depending what you are up to...

Do events allows the current stream of exectution to be suspended while
other code is run but that is not what you are doing. To see doevents in
action try this...

Add 2 command buttons (from the control toolbox) to a worksheet. Place this
code within the sheet itself

Private Sub CommandButton1_Click()
MsgBox "Tada"
End Sub

Private Sub CommandButton2_Click()
Dim lng As Long

For lng = 1 To 100000
Application.StatusBar = lng
'DoEvents
Next lng
Application.StatusBar = False
End Sub

Click button 2 to execute the counter in your status bar. While it is
executing click Button 1. Nothing happens until the code from button 1
completes.

Now uncomment DoEvents and try again.

This time you can suspend the execution of the counter at any point to run
the message box.
--
HTH...

Jim Thomlinson

"Andrew" wrote:
For the code below, if I leave the worksheet alone, the code runs
fine. If I activate a cell by selecting it, and leave it active, the
code doesn't complete. How do I write a code which will complete the
code regardless of what is happening on the sheet?


thanks


Private Sub CommandButton1_Click()
For k = 1 To 10
Cells(k, 1) = k
Start = Timer
Do While Abs(Timer - Start) <= 1 'Waiting 1 sec
DoEvents
Loop
Cells(k, 2) = k + 1
Next
End Sub


What I'm trying to do is difficult to explain, but in a nutshell I
want the code to hold a value of a boolean variable (not a cell) for 1
second and then put the value of that variable to zero. But I don't
want the processor waiting for the 1 second, I want it available to do
other things. So in your code example, if I interrupt it by hitting
command button 1, the counter code continues after a slight delay. In
my code, the counter stops. Why?
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When does DoEvents return? clara Excel Programming 1 August 28th 07 07:32 PM
DoEvents Arne Hegefors Excel Programming 4 October 19th 06 02:13 PM
VBA shell command - issues... JWM6[_2_] Excel Programming 7 April 19th 06 10:59 PM
DoEvents?? Geoff Excel Programming 4 August 18th 05 03:23 PM
Doevents Application Alex J Excel Programming 1 November 30th 03 04:31 PM


All times are GMT +1. The time now is 11:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"