Progress Bar Refresh

Just starting out? Need help? Post your questions and find answers here.
webba
New User
New User
Posts: 9
Joined: Mon Jul 28, 2003 12:04 pm

Progress Bar Refresh

Post 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.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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
webba
New User
New User
Posts: 9
Joined: Mon Jul 28, 2003 12:04 pm

Post 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?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Nevermind... :oops:
Last edited by Kale on Wed Nov 12, 2003 6:47 pm, edited 1 time in total.
--Kale

Image
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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..
webba
New User
New User
Posts: 9
Joined: Mon Jul 28, 2003 12:04 pm

Post 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:
Balatro
User
User
Posts: 15
Joined: Sun Oct 05, 2003 2:27 pm

Post by Balatro »

Webba, try this:

Code: Select all

UpdateWindow_(WindowID())
~ B
Last edited by Balatro on Wed Nov 12, 2003 7:41 pm, edited 1 time in total.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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
; ...
webba
New User
New User
Posts: 9
Joined: Mon Jul 28, 2003 12:04 pm

Post 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:
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

There's something to learn each day! Hopefully you wont make the same misstake twice ;)
webba
New User
New User
Posts: 9
Joined: Mon Jul 28, 2003 12:04 pm

Post by webba »

Well hopefully not. Not tonight anyway cos I'm off to bed now...

Thanks all :D
bye!
Post Reply