Progress Bars

BlitzMax Forums/BlitzMax Programming/Progress Bars

splinux(Posted 2006) [#1]
Could someone explain me why doesn't this code work?


Strict

Local window:TGadget=CreateWindow("My Window",50,50,240,100,,WINDOW_TITLEBAR)

Local progbar:TGadget=CreateProgBar(10,10,200,20,window)

Global count=0

While WaitEvent()
count=count+1
If count<=50
UpdateProgBar progbar,count/50
EndIf

Select EventID()
Case EVENT_WINDOWCLOSE
End
End Select
Wend




tonyg(Posted 2006) [#2]
Because there are no events firing.
This
SuperStrict

Local MyWindow:TGadget=CreateWindow("Progress Bar Example", 40,40,400,400)
Local MyProgBar:TGadget=CreateProgBar(10,20,370,20,MyWindow)

CreateTimer 10

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_WINDOWCLOSE
     End
  Case EVENT_TIMERTICK
    Local t:Int=EventData()
    If t=50 End
    UpdateProgBar Myprogbar,t/50.0

  End Select
Forever
End

was taken from here


Brendane(Posted 2006) [#3]
You are waiting for an event in your while loop for each pass - the only event your app will get is the close event. Add a timer to trigger an event at a set interval and update your progress bar on the timer event :-

Strict

Local window:TGadget=CreateWindow("My Window",50,50,240,100,,WINDOW_TITLEBAR)

Local progbar:TGadget=CreateProgBar(10,10,200,20,window)

Global count=0

Global timer:TTimer = CreateTimer( 200 )

While WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
	End
Case EVENT_TIMERTICK
	If count < 100
		count = count + 1
		UpdateProgBar progbar,count/100.0
	EndIf
End Select
Wend



Brendane(Posted 2006) [#4]
Oops, tony beat me to it :)


splinux(Posted 2006) [#5]
Ok, i'll try to modify the counter to a timer.

Thank you all.