New topic: 

Can't make window visible

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

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        aulay          Post subject: Can't make window visiblePosted: 
Mon Apr 22, 2013 7:03 am                         
Joined: Wed Aug 27, 2008 7:36 am
Posts: 8                I have a simple progress bar,which was working fine up 
to now. I made some coding changes (but in the same version of RS - 2011R1) and 
now I can't get the window to be visible and updated such that it shows.

 the code is:

  counter=counter+1
  WindowA.Run_ProgressBar.Value=(counter/cmax)*100
  WindowA.ProgressText.Text=str(round((counter/cmax)*100))
  WindowA.Refresh

The program runs to the end, the progress bar does nothing and the program 
completes.

If I add a simple MsgBox blow the code above, that returns the focus to the 
window and the progress bar shows up as it should. But that's not a solution! 
[I've toyed about with .Visible = True and .Show but to no avail.]

Any help gratefully received.      
_________________
Mac OS 10.8.3
RS 2011r1  
                             Top                Jason_Adams          Post 
subject: Re: Can't make window visiblePosted: Mon Apr 22, 2013 3:05 pm          
                       
Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1794
Location: Michigan, USA                Hello!

This looks like a hunk of code taken out of a loop context. If that's the case, 
you're going to see exactly the sort of behavior you're getting. The main 
thread is running the loop and not leaving in order to redraw the screen. 
Refresh has been a way of brute forcing this in the past, but it's really not a 
good way of doing things.

For serious work (the sort of things that merit progress bars) it's best to do 
the work within a thread. But [u]do not[/u/ access the UI from within the 
thread (i.e. the progress bar). Instead, use a property of the thread to act as 
a value exchange between the thread itself and a timer which checks the state 
of the thread, and updates the UI itself.

Hope this helps!     
_________________
Windows 7 Ultimate x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult 
and not tried." - G.K. Chesterton  
                             Top                aulay          Post subject: 
Re: Can't make window visiblePosted: Mon Apr 22, 2013 3:58 pm                   
      
Joined: Wed Aug 27, 2008 7:36 am
Posts: 8                Many thanks for this. Yes, it is a piece of code called 
from a loop as you say. 
[On the one hand, it clearly isn't quite inevitable that I would see this 
behaviour (at least in 2011R1) because it was all working fine.
But I have noted a general disapproval of using Refresh, so accept this is "bad 
programming". Naughty me.]

Until I read your response, I was clueless about threads. But having looked at 
the user documentation (http://docs.realsoftware.com/index.php/Thread), which 
helpfully gives a progress bar example, I will try to get on top of it.

Thanks again!      
_________________
Mac OS 10.8.3
RS 2011r1  
                             Top                aulay          Post subject: 
Re: Can't make window visiblePosted: Mon Apr 22, 2013 5:37 pm                   
      
Joined: Wed Aug 27, 2008 7:36 am
Posts: 8                Hi Jason, thanks again. mission accomplished!      
_________________
Mac OS 10.8.3
RS 2011r1  
                             Top                Jason_Adams          Post 
subject: Re: Can't make window visiblePosted: Mon Apr 22, 2013 8:07 pm          
                       
Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1794
Location: Michigan, USA                Great! I'm glad it worked out and you 
got a new tool on your belt.     
_________________
Windows 7 Ultimate x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult 
and not tried." - G.K. Chesterton  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 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