Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The best way to show program status? 5

Status
Not open for further replies.

Polariz666

Programmer
Jul 22, 2004
21
SE
Hi guys.

I have a program that does alot of SQL cycles and can take as long as 40 seconds to load in all the relevant data. At the moment, a form appears to show that the program is working (And taking up all of the CPU power), and disappears when the cycles have finished. However the forms are not drawn properly (Even though they are made to appear first in the code before the main execution starts), and also sometimes they do not get hidden again once the processing has finished.

What would be the best way to show status? And how would I go about implementing it.

Regards,

Mike.
 
Have you considered a progress bar? There are some pretty nice ones available as examples in the many source banks on the web. A basic one should be available is Visual basic manuals.
 
Yeah I had considered it but haven't a clue how to implement it. I'll take a look through the help file, cheers.
 
If you use Microsoft common controls 6 component you get the Progress bar option on your components tab. All you need to do is increment it every time your program loops.

EG.

Private Sub Command1_Click()
Do Until ProgressBar1.Value = 100
'whatever codehere
ProgressBar1.Value = ProgressBar1 + 1 'depending how many loops change increment
DoEvents
Loop
End Sub

David Lerwill
"If at first you don't succeed go to the pub"
 
Are all of your queries in the Form_Load event?
You might want to consider to move this to a procedure that can be called after the form load event ... maybe a load menu option or a load button - then you'll be able to display the progress bar ..

Just my 2c

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
No the queries are only found when either the user clicks a button or drops down a combo box and makes a selection. The user may not always wish to run the same query so putting it in form load would waste alot of the user's time - especially considering there's around 1.2 million records altogether, that are whittled down gradually to locate the exact data the user requires.

Thanks for the help guys, i'll read through and see what I can make.
 
----------------------------
Quote from dwlerwill:

EG.

Private Sub Command1_Click()
Do Until ProgressBar1.Value = 100
'whatever codehere
ProgressBar1.Value = ProgressBar1 + 1 'depending how many loops change increment
DoEvents
Loop
End Sub
----------------------------

I can see that this would be a possible way to implement this, however the problem is that the program uses while loops to cycle through the recordsets. The problem is obviously that the number of loops is always variable. For example, this is a set of queries that happen when one particular button is pressed:

================

rs.Open "SELECT * FROM table", db1, adOpenDynamic

While Not rs.EOF

var = rs!tableHeader

rs2.Open "SELECT * FROM table2 WHERE tableHeader2 = var ", db2, adOpenDynamic

While Not rs2.EOF
'Fill in combo boxes and labels etc
rs2.MoveNext
Wend

rs2.Close

rs3.Open "SELECT * FROM table2 WHERE tableHeader2 = var ", db2, adOpenDynamic

While Not rs3.EOF
'Fill in combo boxes and labels etc
rs3.MoveNext
Wend

rs3.Close

rs.MoveNext

Wend

rs.Close

===============

As you can see, this can get quite complex, but also has no predetermined end status. Any help appreciated.

Mike.


 
Why not consider having an avi that start when you enter your procedure that executes the queries and stops at the end of the procedure .... With a nice message that says:
"Information loading... Please be patient"

It could be on an invisible frame on the form ...

???

[flowerface]

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Because the current code is like so:

-----------------
Private Sub Button_CLick

form.show / label.Caption = "Working" (Ive tried both)

Do the code

form.Hide / label.CAption = "Done."

End Sub
-----------------

In both cases, the form is either not drawn properly (IE it has labels and pics on it to show the system is working, but the form just gets drawn as a white blob on the screen), so it's almost as if the program does a half arsed job of drawing it then just carries on with the SQL - using up all the Pc's CPU power. Also sometimes the form (Or avi as you suggested) doesnt form.hide like it should do after the code has executed. The users for this system arent the most PC-familiar people ive ever worked with, so they're likely to leave the PC alone while the message is still present.

Mike.

 
I have the following code that I use in a form that executes a DTS package ... aniMove is an Animation control.
Maybe for your purposes - DoEvents might work ..

Private Sub DoDataTransfer()
'This procedure will use the DTS Package object to run the DTS package remotely

On Error GoTo errTrap

'Executing DTS package code
'This takes about 2-3 minutes and the animation runs
'on terminal server without any white blotches on the
'screen.

Animation_End

Unload frmDTS
Set frmDTS = Nothing

Exit Sub

errTrap:
MsgBox "My message", vbCritical + vbOKOnly, Me.Caption

Unload frmDTS
Set frmDTS = Nothing

End Sub

Private Sub Animation_Start()
'Start animation

aniMove.AutoPlay = True
aniMove.Open App.Path & "\FILEMOVE.AVI"
aniMove.Play

End Sub

Private Sub Animation_End()
'Stop animation

aniMove.AutoPlay = False
aniMove.Stop

End Sub

Private Sub Form_Load()

Me.HelpContextID = 20
Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

Animation_Start
Timer1.Enabled = False
DoDataTransfer

End Sub

Hope this is of help to you
Cheers

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Bloomin marvelous, doEvents works a treat. Thanks chap.

Mike.
 
As far as the improperly drawn forms or controls go, try throwing in a few DoEvents or Refresh statements. Give it a Refresh just after you've made a change to something but right before you call a processor-intensive operation.

If you're looping, a DoEvents inside the loop is a nice way of keeping the program somewhat responsive. If the loop cycles very frequently though, the DoEvents will begin to cause a noticeable performance hit. Usually though, I find the improved responsiveness worth the slower performance. I think users would rather wait an extra second or two than be left wondering if the program has crashed.
 
FYI

This thread shows the use of DoEvents. Do a search on this forum for DoEvents before implementing this as a solution.

Matt
 
Good advice.
The biggest concern that DoEvents causes me is that you must manually control user interaction when you use it. Basically any other actionable control has to be manually disabled because their events will fire if a user happens to click on them while your loop is running. If you're feeling dangerous you can sometimes use this to simulate multithreading but generally it's just trouble.
 
If you are using intensive loops for many iterations, use DoEvents on say every 100 iterations, otherwise concentrate on the processingin your loop.

This keeps the form updated, and frees some processing to keep the windows drawn correctly.

VBrit
 
I'm having a similar issue, in that my form just kind of freezes while the processing goes on. Unfortunately, my processor intensive operation isn't in a loop (which I guess would lend itself to DoEvents and progress bars).

My program copies files across a VPN with a single FileSystemObject Copyfile command. Often the files are fairly biggish (>3MB) so it takes a while and during that time, the form will not redraw.

I tried putting an animated gif on the form (showing a file being transferred) which was great, except that as soon as the file copying started, the animation stopped, only to restart once the copying was finished! (Kind of the wrong way round...)

I just want to have some kind of visual activity to stop users from getting impatient and crashing out of the program... Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top