From: mynamehere@comcast.net   
      
   "steve marchant" wrote in message   
   news:448b421d$1_4@mk-nntp-2.news.uk.tiscali.com...   
   > trying to learn VB6. Simple counting loop which counts to 8 in 1 sec   
   > intervals, then starts from 1 again and repeats.   
   > Have two Command buttons on the form. Cmd1 starts the counting, and I need to   
   > know how to stop it with Cmd2.   
      
   If you use a Do Loop like that, then you need to use DoEvents, as Dikkie Dik   
   said.   
   So here is an example: Lesson 1, Control Your Loops.   
      
   You need a variable to control the loop, which Cmd1 sets one way, and Cmd2 sets   
   the other way.   
   It must be declared in the general section, not inside a procedure.   
   You need to check that variable in both do loops.   
   You need to use DoEvents in the loop, so the click of Cmd2 can do its work.   
   It is also safer to check for Timer() > x + 1, not Timer() = x + 1.   
      
   Something like this:   
      
   Private StopGotClicked As Boolean   
      
   Private Sub Command1_Click()   
    Dim x As Single   
    Dim m As Integer   
      
    StopGotClicked = False   
    m = 1   
    Cls   
      
    Do Until StopGotClicked   
    Print m   
    x = Timer()   
    Do Until StopGotClicked Or Timer() > x + 1   
    DoEvents   
    Loop   
    m = m + 1   
    If m > 8 Then m = 1   
    Loop   
      
    Print "stopped"   
      
   End Sub   
      
   Private Sub Command2_Click()   
    StopGotClicked = True   
   End Sub   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|