home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 10,089 of 10,840   
   Steve Gerrard to steve marchant   
   Re: stuck in loop. Please help   
   10 Jun 06 16:36:39   
   
   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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca