New topic: 

question about loop behavior

<http://forums.realsoftware.com/viewtopic.php?t=47189>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        vkelmenson          Post subject: question about loop 
behaviorPosted: Wed Mar 06, 2013 8:17 pm                         
Joined: Wed Mar 06, 2013 7:48 pm
Posts: 1                Hello everyone. I am a new member of the forum. I have 
been programming for many years and a RB user since 2005. I am a hobbyist 
programming for my own amusement. 
  I have run into a problem with the following code.

  // runs the specified number of days
  
  dim i as integer  // loop counter
  dim days as integer // the number of days to run
  
  // find number of days to run
  days = val(NumOfDays.text)
  
  // loop through that number of days
  for i = 1 to  days
  RunOneday(animals(), TheWorld())
  
  // show progress
  if i mod 1000 = 0 then
  App.DoEvents()
  DaysRun.text = str(i)
  end if
  next
  
  // show world
  clr
  DrawWorld(TheWorld())
  
 This is the main loop from an evolution simulation. When running for a large 
number of days(several millions) it takes over an hour. 
I coded a routing to update me on the progress every 1000 days. If run as above 
it works fine. However, if I comment out the DoEvents 
line, the textarea is not updated until the routine finishes. Why is this ? 
Obviously the loop is keeping control. The documentation says not to use 
DoEvents in a single threaded application which this is. The code is working 
fine. I am just curious what is happening? Thanks in advance for any help that 
you can give me. Victor
I am using RS 2012 R2 on Mac osX 10.5.8   
                             Top                timhare          Post subject: 
Re: question about loop behaviorPosted: Thu Mar 07, 2013 12:37 am               
          
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12111
Location: Portland, OR  USA                I would recommend you put the code 
into a thread.  As is, it will make your app appear unresponsive while it runs. 
  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to