Page 1 of 1

Progress Bar Refresh

Posted: Wed Nov 12, 2003 1:26 pm
by webba
Hi all!

I wonder if any one can help?? :D

I have a loop that processes a text file. I have a progress bar that should display the progress of the routine - Im seting the gadget state inside the loop, but the progress bar gadget doesn't seem to update until the loop finishes.

I guess this is something to do with event processing and window refresh but I can't wotk it out. I've done a search and tried a couple of things with delay() and windowevent() but to no avail...

as usual any help greatly appreciated.

Posted: Wed Nov 12, 2003 2:21 pm
by Pupil
if you do this, in your routine, right after you've updated the gadgetstate, you should hopefully be able to see the progressbar update..

Code: Select all

While WindowEvent()
Wend

Posted: Wed Nov 12, 2003 3:36 pm
by webba
Thanks for the suggestion Pupil.

It doesn't seem to work with my code though...!? :cry:
Here's the relevant snippet...

Code: Select all

     .....
     .....
     UseFile(#Source)
     sBuffer = ReadString()
     lLine = lLine + 1
     SetGadgetState(#Gadget_1, ( ( Loc() / Lof() ) * 100 ) )
     While WindowEvent()
     Wend
    Until Eof(#Source)
any other suggestions?

Posted: Wed Nov 12, 2003 5:34 pm
by Kale
Nevermind... :oops:

Posted: Wed Nov 12, 2003 5:48 pm
by Pupil
Kale wrote:AHA! IIRC 'ReadString()' reads the entire file to a string NOT a single line! so the progressbar is updated all in one go after the entire file is read because '( Loc() / Lof() ) * 100' = 100%. I think your best bet is use 'ReadData()' then process this string for CRLF's for your lines.
??
This is what the manul says about ReadString()
PureBasic Manual wrote: Read a string on the current opened file until an 'End Of Line' character is found (Unix and DOS file formats are supported).
So this command reads from the file until a EOL char (Dos format = chr(13)+chr(10), UNIX format = chr(10)) is found and puts what was read upto that character into the string..

Posted: Wed Nov 12, 2003 7:31 pm
by webba
Just to confirm...

ReadString() is working as per the manual. One of my source files is 500K and I doubt that PB's string routines would let me load that into 1 string. Besides, the logic of the routine wouldn't allow it and it's working fine in all other respects.

I must say I'm surprised that as of this post 80 people have looked at this problem and there doesn't seem to be a solution. Surely the main use for a progress bar is as I'm trying to use it. ie in a 'long' routine to give the user an indication that the app hasn't just locked up.

Hasn't anyone else tried to use it this way?

I'm sorry if I'm coming over all stressed. Yes I need to chill out! 8O

I Wonder if there's an API to force a repaint of the window / gadget. I seem to remember doing something like that in VB... :roll:

Posted: Wed Nov 12, 2003 7:35 pm
by Balatro
Webba, try this:

Code: Select all

UpdateWindow_(WindowID())
~ B

Posted: Wed Nov 12, 2003 7:39 pm
by Pupil
hmm, i'm wondering if it's an integer issue..as Loc()/Lof() always equals '0', try this and see if it's working:

Code: Select all

;...
progress_f.f = Loc()/Lof()*100
; maybe you need to store this in an intgerer again to get
; proper float->integer transformation, you can try without.
progress.l = progress_f
SetGadgetState(#Gadget_1, progress)
While WindowEvent()
Wend
; ...

Posted: Wed Nov 12, 2003 7:52 pm
by webba
:oops: :oops: :oops:

Ha Ha!

Pupil saves the day!
i'm wondering if it's an integer issue
Yes. An integer issue. It's a case of PEBKAC*

Thanks pupil. If I had any sense I'd have tried setting the progress bar to some intermediate values in the routine or debugged the value I was setting it to...

Anyway, thanks again :D

*Problem Exists Between Keyboard And Chair :oops: :oops: :oops:

Posted: Wed Nov 12, 2003 7:58 pm
by Pupil
There's something to learn each day! Hopefully you wont make the same misstake twice ;)

Posted: Wed Nov 12, 2003 8:06 pm
by webba
Well hopefully not. Not tonight anyway cos I'm off to bed now...

Thanks all :D
bye!