Click to See Complete Forum and Search --> : GUI for showing progress


Dr_Michael
December 14th, 1999, 03:47 AM
I have created a program which makes a long time process to a database. I want to show something to the user, maybe a progress bar, or another form with steps, or something else? Any ideas? And code of course!
Thank you!

Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece

Lothar Haensler
December 14th, 1999, 04:15 AM
yes, I WOULD use a progress bar.
More important: use the asynchronous operations in ADO!
You'll get a FetchProgress Event on your Recordset object, essentially getting progress status for free.

Ravi Kiran
December 14th, 1999, 04:35 AM
Hi,
It depends on your situation actually.
Like if you have access to the code, that is taking long time, and you can modify it, then
you can put code lines like RaiseEvent etc to give back the percentage finished.

But if you dont have access to code, or from your code, it is just a single function call that is taking long time, then only way is to redesign the app.. and run the time taking processes on a thread. For this unfortunately, you have to do the rough way.. CreateThread etc, which is not all that easy to get it working.

Assuming your case is first type, you can take two approaches:
One: Place a Progress bar on the form, and as each step finishes, you can set the value of progress bar. This i would call "direct method".
Function TImetaking()
pbar.value = 0
pbar.Max = 5 ' 5 steps
... do fist step of time taking process
pbar.value = 1
... do 2nd step of time taking process
pbar.value = 2
..
end Function

If you have this thing in a loop, you can use the loop variable to update pbar value

If you have the code in a Class, then you can RaiseEvents

Public Event PercentFinished( byval i as integer, byval n as integer, byref cancel as boolen)

Function TImetaking()
dim bProceed as boolean
bProceed = True
RaiseEvent PercentFinished(0,5 , bproceed)
if bProceed = False then exit function
... do fist step of time taking process
bProceed = True
RaiseEvent PercentFinished(1,5 , bproceed)
if bProceed = False then exit function
... do 2nd step of time taking process
RaiseEvent PercentFinished(2,5,bProceed)
..
end Function

This way you can also give the logic a chance to be stopped, if required. It is up to the event handler to implement, what ever UI updations he wants to do. in form foe ex:
dim withevents m_myclsptr as EventClass
'
Private sub m_myclsptr_PercentFinished(byval i as integer, byval n as integer, bproceed as Boolen)
pbar.value = i
pbar.Max = n
'or
Label.caption = "Finished :" str(i) &"/" & str(n)
'or what ever
end sub

RK

Chris Eastwood
December 16th, 1999, 07:32 AM
If you want a progress bar and some fancy animated dialogs that you can reuse over and over, take a look at :

http://codeguru.developer.com/vb/articles/1638.shtml

- I'll get around to updating it one day to use the AVI's stored in the Windows DLL's.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Dr_Michael
December 16th, 1999, 07:54 AM
Nice article, thanx. Tell me how can I add the required reference to this project.
Unfortunately, this is not siutable for my application, because my program is doing a proccess of improving data from a database to another... Any other idea???

Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece

Chris Eastwood
December 16th, 1999, 08:29 AM
I just had a whole bunch of trouble trying to get the code from that old article working on this machine. Here's what you need to do :

1. Load the CGAnimation.vbp project first
- Ignore the errors and add in the frmAnimate.frm manually (if you get an error)

2. Compile the CGAnimation project to make the DLL

3. Load the TestAnim.vbp file

4. Go to Project->References and set a reference to CGAnimation.dll using either 'browse' or locate it in the list of available references.

5. Run the project (and look at the code to see how it works !


I thought that this would have been ideal for showing that your program is busy processsing those DB records - it also shows how to use the ProgressBar while something else is happening.


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb