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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Progress...How to?

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
0
16
US
I would like to do two things to display the progress of a program.


1. Display text to show the progression of the program
2. Display a progress bar

My problem is that there are several routines that run for the program and I am not sure how to use the progress properties to track the progress of the program. A form calls the routines which reside in a module.

My other problem is I was trying to figure out what to use to display the text that displays what is going on in the program. I thought about using the lable control, but for the life of me I could not figure out how to get the text in the caption. I tried assigning the text to a global variable and then assigning that value to the caption property in the change event, but nothing was displaying in the label.

I need help, or I need to take a break. I could just be thinking this is all harder than it needs to be.

Thanks for your help.

Pam
 
1. The best bet is to use a PictureBox control. (the first control on the standard toolbox). The advantage of the picturebox control is that it has an align property that will keep the control attached to a part of the form (such as the bottom) and will auto-resize with the form. Drop one on your form and set the align property to a desired setting (top bottom left etc.)

2. Next send the progress (as a string) at each step of the program to the picturebox control Print method. It may be best to have a Sub routine to handle this. Here's an example:
assuming your PictureBox control has been named "picStatus"

<In each area you want to display a status>
<such as the top of each routine you call during your processing.>
Call ProcessStatus &quot;The Status message here...&quot;

<Create a Sub to process your status messages.>
Public Sub ProcessStatus(Status As String)
picStatus.Cls
picStatus.Print Status
End Sub

If you are using classes, progress reporting gets even more exciting. Let me know if you need help with that.

good luck...
Fishy Stu.
 
Fishy:

Thanks for your reply. I am going to try your suggestion.

I am realatively new to programming in general and welcome the advice and help.

As I was looking through one of the books that I have and I began to wonder if I should use classes. I am still not comfortable with knowing when to use what. I guess this lets you know that no, I am not using classes, but I am for knowing how I would use classes in this case.

Thanks again.

I will let you know how I do with your advice.

Pam
 
OK Fishy:

This is what I did.

I did your steps 1 and 2 above, but what I did for step two may be considered bad programming practice, at least according to Francesco Balena (author of Programming Microsoft Visual Basic 6.0).

Here is what I did.


1. Added a picturebox control to frmProgress. This form is called by the main form. The main form (frmRunProgram)is hidden and frmProgress is loaded using frmProgress.Show. The main form contains the calls to the standard module that runs all the routines that need to be done.

2. I created the procedure ProcessStatus in the standard module. This is where I think I have the bad programming. This is what the procedure looks now (and it works).

Public Sub ProcessStatus(Status as String)
'bad programming???
frmProgress.picProgress.Cls
frmProgress.picProgress.Print Status
End Sub

I have also read in two places that using standard controls instead of lightweight controls uses up more system resources, but I guess I have not other option than to use the PictureBox control until I can figure out how to create an object and use With Events???


Thanks again for your help.
 
Pam

Balena's book is very good. I'm glad to hear you have it. Is there any reason you are using a separate form for the progress? you could just drop the pictureBox on the main form and make life much simpler for yourself. As far as lightweight controls and saving resources... Is this a standard standalone or client server app? or a Web based solution? If it is a standalone app my feeling is i don't worry about resources with controls like this. Machines today should have more than enough power to process apps with hundredes of controls like these. As for the classes and posting progress, use the Event model. It's simple.... of course your class would do more than this but this class has all the progress status stuff intact.

In the class:
* Event <name>(<arguments>)
* RaiseEvents

In the form:
* Dim WithEvents MyClass1 as MyClass
* Set MyClass1 = New MyClass
* Sub ProcessStatus(<arguments>)

Example:
<Class code (MyClass.cls)>
Option Explicit

Event ProcessStatus(Status As String)

Private Sub Class_Initialize()
' you can put some code here, or none at all Pam...
End Sub

Private Sub Class_Terminate()
' more junk here, or none at all...
End Sub

Public Sub YourSub1()
RaiseEvent ProcessStatus(&quot;Processing YourSub1...&quot;)
' more code here if ya want...&quot;
End Sub

Public Sub AnotherSubForYou()
RaiseEvent ProcessStatus(&quot;Processing AnotherSubforYa...&quot;)
' more code here if ya want...&quot;
End Sub
**********

<In the form code (.frm)>
Dim WithEvents MyClass1 as MyClass

Private form_load
Set MyClass1 = New MyClass
End Sub

Sub ProcessStatus(Status As String)
PicStatus.Cls
PicStatus.Print Status
End Sub

***
Cod liver oil...
 
Cod Liver Oil??? ick!!! B-).


Thanks for the example. I will have to read more about classes before I actually use the code, but Thanks for the example.

Also, back to one of my original questions. How would I include a progress bar (the one that increments the blue bar as the program progresses).

Thanks a bunch for your help.

Pam
 
Oh...I forgot to say even if I put the Picture Control on the main form, I still have to set up the Process Status procedure the way I did so I can call the procedure from within the routine, right?

P
 
Disregard that last post regarding the procedure.

I just need help with a progress bar.


Pam
 
You need to add the Microsoft Common Controls 6.0 (SP4) to your toolbox. You do this by right-clicking on an empty spot in the toolbox and selecting &quot;Components...&quot;. Now find the above component and add it to your project by checking the checkbox.

Now that it's in your project, you'll see the icon appear in the toolbox. Drag & Drop it onto your form. Usually the only properties you have to change are the name (if you want to), the min, and the max. As their names imply, the min and max are the values represented by the progress bar being empty and full.

To see one in action, add a progressbar and a timer control to a form. Then add the following code:
[tt]
Option Explicit

Private Sub Form_Load()
ProgressBar1.Value = 0
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
If ProgressBar1.Value < 99 Then
ProgressBar1.Value = ProgressBar1.Value + 2
Else
Timer1.Enabled = False
End If
End Sub
[/tt]

Hope this helps.

Chip H.
 
Ah yes! the old colored status bar on the form trick eh? Remember Maxwell Smart?

Pam, you mentioned Balena's book. If you have it, check out pages 346 through 348 for an example of exactly what you are trying to do using the picturebox control I mentioned. You just need to use the Line method, CurrentX , CurrentY properties and add the code to the ProgressStatus routine you have. Page 348 gives you an example of how you could do it.

RE: Your ProgressStatus routine:
The only advantage of having a Progress routine is to make calling progress posting from many place easier. You could put the actual code in each location of the program where you update the status, but that's alot of extra coding!

The example Chiph sent you will give you a bar that will progresses accross over time. The picturebox example will give you a progress bar that will be incremented when each task in the app is completed (or started).

Never had Cod liver oil. Does sound disgusting though!
Fish Head...
 
Hi Chip and Fishy...

I will give it a whirl.

I have looked at several examples, somehow missed the picture control one in Balena's book (oops), and could not figure out how to set the min and max if I had no idea what to set them as. And I have not caught on yet to Timer Control. I have no idea why, just call me slow. The light bulb just has not gone on yet.

I will keep you posted. I have a lot of things to do before Wednesday (I am going on vacation) and I do not know when I will get back to this project.

Thanks a bunch.

Pam
 
Pam -

The Timer control I used was just a way to get the progress bar to increment (made for a cooler demo :-0 )

Let's say you've got 7 lengthy steps to complete in a process. You'd set the min property to 0, and the max to 7. 0 indicates that you haven't begun yet, and 7 say's you're done. You'd use an integer variable to keep track of what step you were on, incrementing it as you go along. So:
[tt]
ProgressBar1.Min = 0
ProgressBar1.Max = 7
ProgressBar1.Value = 0

For iStepCount = 1 to 7
[tab]Select case (iStepCount)
[tab]Case 1:
[tab][tab]' Do step 1
[tab]Case 2:
[tab][tab]' Do step 2
[tab]Case 3:
[tab][tab]' Do step 3
[tab]Case 4:
[tab][tab]' Do step 4
[tab]Case 5:
[tab][tab]' Do step 5
[tab]Case 6:
[tab][tab]' Do step 6
[tab]Case 7:
[tab][tab]' Do step 7
[tab]End Select

[tab]ProgressBar1.Value = iStepCount
Next iStepCount
[/tt]

Hope this helps.

Chip H.
 
Hi CodFish,

I use the progress bar control in my app and it works out fine. However, it does involve more coding, which I would like to avoid. I have a demo program that shows the use of a picture box and it seems interesting, but for the life of me I do not get how it can work in my program. All the code is in the form that has the picture box, but I am so used to placing code in the various places from where the progress bar is called. How would the picture box thing work with a recordset or with compacting a database? Since all the code is in the form that houses the picture box, how is status updated without having to code all through the program for it. In this demo the max value is hardcoded, which makes it simple, but in most cases the max value is unknown.

Having it all in one place would be excellent, but could you please give me an example of this with both a record set and the compacting a database? As it stands now, when I compact the database, I use a message box to inform the user of what is going on.

Thanks for any help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top