473,801 Members | 2,341 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a progressbar display shared class function

How can I create a shared function to display process progress that can be
called from other routines within an application? Any example that I can
follow?
Thanks
Bill
Nov 20 '05 #1
2 3188
Hi Bill,

You can call the Value property from other "routines" (methods), as long as
the progress bar object is accessible to those methods. If you have a form
with a progress bar, that object is accessible to all methods in the same
form class.

However, to change Value property from other classes, you need to use a
different strategy.
You have several choices, some simpler, some more complex (callbacks,
threads... nasty stuff!).

I'm gona show you a simple way:

Imagine you have a class called MyClass with a method called MyTask where a
long job will be done, and you want to track progress with a ProgressBar1
control on Form1. When you call MyTask sub, you can pass as argument the
ProgressBar1 control. Example:

Dim objMyClass As New MyClass
objMyClass.MyTa sk(ProgressBar1 )

This way, your class method needs to be changed to receive ByRef the
progress bar control. Note the ByRef (not ByVal), so that the object can be
changed.

Public Class MyClass
Public Sub MyTask(ByRef objProgBar As ProgressBar)
While donework < totalwork
' do main job
' show progress
objProBar.Value = Math.Round(done work * 100 / totalwork)
' not using threads, its better to order the events
Application.DoE vents()
End While
End Sub
End Class

That's it. Lets just consider a scenario where you dont call the MyTask
function from the object where the progress bar is. For instance if you have
two forms, progress bar is on Form1, and the call to MyTask is on a button
click event on Form2. No problem. If MyClass instance is already created
when Form1 runs, or it is created by Form1, you can just create a variable
on MyClass to receive the control, and pass it at Form1:

Dim objMyClass As New MyClass
objMyClass.Prog ressBarControl = ProgressBar1

If MyClass instance is only created by Form2, no problem. Create a public
variable on Form2:

Public ProgressBarCont rol As ProgressBar

So that you can use it when creating Form2 (assuming Form1 creates Form2):

Dim frmForm2 As New Form2
frmForm2.Progre ssBarControl = ProgressBar1
frmForm2.Show()

When Form2 creates MyClass and calls MyTask, can you what is on
ProgressBarCont rol variable.

Dim objMyClass As New MyClass
objMyClass.MyTa sk(ProgressBarC ontrol)

As I said there are other ways to handle your challenge. Advanced code,
taking full advantage of Framework, probably would thread the MyTask Sub, or
even thread pool what is supposed to be done there. That is a little bit
hardcore, and I think you should try this first.

Best regards,
Mario
"Bill Nguyen" <bi***@jaco.com > wrote in message
news:eN******** *****@TK2MSFTNG P11.phx.gbl...
How can I create a shared function to display process progress that can be
called from other routines within an application? Any example that I can
follow?
Thanks
Bill

Nov 20 '05 #2
I use that method successfully!
I "invented" it because I needed to do it.
Surprisingly, it actually worked!
--
Joe Fallon


"Mario" <mz******@DONTW ANTSPAMmail.pt> wrote in message
news:Ov******** ******@TK2MSFTN GP11.phx.gbl...
Hi Bill,

You can call the Value property from other "routines" (methods), as long as the progress bar object is accessible to those methods. If you have a form
with a progress bar, that object is accessible to all methods in the same
form class.

However, to change Value property from other classes, you need to use a
different strategy.
You have several choices, some simpler, some more complex (callbacks,
threads... nasty stuff!).

I'm gona show you a simple way:

Imagine you have a class called MyClass with a method called MyTask where a long job will be done, and you want to track progress with a ProgressBar1
control on Form1. When you call MyTask sub, you can pass as argument the
ProgressBar1 control. Example:

Dim objMyClass As New MyClass
objMyClass.MyTa sk(ProgressBar1 )

This way, your class method needs to be changed to receive ByRef the
progress bar control. Note the ByRef (not ByVal), so that the object can be changed.

Public Class MyClass
Public Sub MyTask(ByRef objProgBar As ProgressBar)
While donework < totalwork
' do main job
' show progress
objProBar.Value = Math.Round(done work * 100 / totalwork)
' not using threads, its better to order the events
Application.DoE vents()
End While
End Sub
End Class

That's it. Lets just consider a scenario where you dont call the MyTask
function from the object where the progress bar is. For instance if you have two forms, progress bar is on Form1, and the call to MyTask is on a button
click event on Form2. No problem. If MyClass instance is already created
when Form1 runs, or it is created by Form1, you can just create a variable
on MyClass to receive the control, and pass it at Form1:

Dim objMyClass As New MyClass
objMyClass.Prog ressBarControl = ProgressBar1

If MyClass instance is only created by Form2, no problem. Create a public
variable on Form2:

Public ProgressBarCont rol As ProgressBar

So that you can use it when creating Form2 (assuming Form1 creates Form2):

Dim frmForm2 As New Form2
frmForm2.Progre ssBarControl = ProgressBar1
frmForm2.Show()

When Form2 creates MyClass and calls MyTask, can you what is on
ProgressBarCont rol variable.

Dim objMyClass As New MyClass
objMyClass.MyTa sk(ProgressBarC ontrol)

As I said there are other ways to handle your challenge. Advanced code,
taking full advantage of Framework, probably would thread the MyTask Sub, or even thread pool what is supposed to be done there. That is a little bit
hardcore, and I think you should try this first.

Best regards,
Mario
"Bill Nguyen" <bi***@jaco.com > wrote in message
news:eN******** *****@TK2MSFTNG P11.phx.gbl...
How can I create a shared function to display process progress that can be called from other routines within an application? Any example that I can
follow?
Thanks
Bill


Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4366
by: Steve Teeples | last post by:
Is there a way for code from one class of C# to send a communication to a progressbar in another class to update the bar during runtime? -- Steve
8
19634
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied. pBar1.Minimum = 1; // Set Maximum to the total number of files to copy. pBar1.Maximum = 4; //filenames.Length;
0
1014
by: tlemcenvisit | last post by:
Refreshing a progressBar Hello I have a function which takes much execution time. I’d like to display its progress in a progressBar. For the moment I make like that: for(y=0;y<height;y++) {..... progressBar1->Value=((double)y*100/height); } But I think that this method makes my function even slower.
1
6070
by: AnAnimal | last post by:
How would I display the Windows FILECOPY.AVI above a ProgressBar control?
4
4780
by: pmcguire | last post by:
Rather than putting a progress bar on all of my forms to show progress during time consuming tasks, I made a form called frmProgress with 2 controls, a Label and a ProgressBar. Suppose I expose 1 property -- prgValue (the Value of the ProgressBar); how do I use threading so that my time consuming task will open and display frmProgress as well as continually update prgValue (and display its progress), and then close frmProgress upon completion? ...
4
1649
by: Joe HM | last post by:
Hello - I have a Base Class where I want a New() implemented that can be called from the outside. This New() should create an instance of the appropriate cDerivedX Class ... The following shows a scenario where it was determined that cDerivedA is needed based on a configuration file. Dim lInstance As New cBase()
24
2846
by: M O J O | last post by:
Hi, Instead of doing this.... Public Class Form1 Public Shared Sub CreateAndShow() Dim f As New Form1 f.Show() End Sub
10
2115
by: tshad | last post by:
I have a Dll I created in VS 2000. The namespace is MyFunctions and the Class is CryptoUtil. I have a program that is using the Class but it can't access it directly. I have a class (below) called CryptoUtil. The functions are Shared functions. I have this Dll in the bin folder of my program. If I don't reference it - it can't seem to find it. If I have:
11
5392
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function, fGetPerformanceGrade(SalesPersonID as Long) as String to retrieve that salesperson's grade (e.g. A+, A, A-, B+, B... D). Also one other function, fGetMonthlySales(SalesPersonID as Long) as String to get their sales figure, e.g. "$87K". I want web visitors to be able to click...
0
9555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10515
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10260
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9100
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.