473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to increment form1.progressbar from module1

I have a module that is called from Form1 that performs a long process.

I have a Progressbar on Form1 that I need to increment to show the user
that stuff is happening.

I added this code to Form1:

Public Sub IncProgBar()
ProgressBar1.Increment(1)
ProgressBar1.Update()
End Sub

However the sub is not visible from Module1.

How can I increment the progressbar from the module?

*** Sent via Developersdex http://www.developersdex.com ***
Dec 21 '05 #1
1 3545
Terry,

"Terry Olsen" <to******@hotmail.com> schrieb:
I have a module that is called from Form1 that performs a long process.

I have a Progressbar on Form1 that I need to increment to show the user
that stuff is happening.

I added this code to Form1:

Public Sub IncProgBar()
ProgressBar1.Increment(1)
ProgressBar1.Update()
End Sub

However the sub is not visible from Module1.


You will have to make a reference to either the form or the control avilable
to the method defined in the module. This can be accomplished by adding a
parameter to the method which takes a reference to the form or control.
However, I prefer a solution which decouples the form and the worker class
and makes the worker class reusable. To do so, define an event in the
worker class which gets raised when progress changes. The client form which
uses the class can add a handler to the progress change event and update the
user interface accordingly.

\\\
Public Class FooWorker
Public Event ProgressChanged( _
ByVal sender As Object, _
ByVal e As ProgressChangedEventArgs _
)

Public Sub DoWork()

' Perform operation here.
For i As Integer = 1 To 100
RaiseEvent _
ProgressChanged( _
Me, _
New ProgressChangedEventArgs(i)
)
...
Next i
End Sub
End Class

Public Class ProgressChangedEventArgs
Inherits EventArgs

Private m_Progress As Single

Public Sub New(ByVal Progress As Single)
Me.Progress = Progress
End Sub

Public Property Progress() As Single
Get
Return m_Progress
End Get
Set(ByVal Value As Single)
m_Progress = Value
End Set
End Property
End Class
///

Client class using the worker object:

\\\
Private WithEvents m_Worker As New Worker()

Private Sub m_Worker_ProgressChanged( _
ByVal sender As Object, _
ByVal e As ProgressChangedEventArgs _
)
Me.LabelProgress.Text = CStr(e.Progress)
End Sub

Private Sub Button1_Click(...)
m_Worker.DoWork()
End Sub
///

The sample above doesn't implement the full event pattern used in the .NET
Framework. I suggest to read the chapters about events in the documentation
in order to get a broader view on the topic.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 22 '05 #2

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

Similar topics

1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
7
by: Terry Olsen | last post by:
I'm trying to make my app source easier to read & follow by breaking up the code into modules. One module has the fileIO routines, another module has the sockets routines, etc. However, I can't...
3
by: Mitchell Vincent | last post by:
In other programming languages I've been able to easily change the style of a progress bar between smooth and blocked. I find that is either really hidden or impossible in .NET. Am I missing...
3
by: patang | last post by:
Very simple question. I have a project with multiple forms and a Module1. In Module1 I have written the connectionstring: Module Module1 Public connectionstring =...
4
by: thomasp | last post by:
Using VB2005 Beta 2 If I use Application.Run(New Form1) in the below code. Then code like TAM.Form1.rtbAllAcq.Text = aryStatistics(0) that is used to update a richtextbox on Form1 does not work....
2
by: Svein Erik | last post by:
C# 2.0 How can i update my progress bar on Form1, from Form2? Form 2 contains a button that is supposed to update the progressbar on Form1 by 5 in value. I can't find out how to do this, please...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
2
by: lewisms | last post by:
Hello all, I am quite new to c++/. Net so please don't shoot me down for being a newbie. Any way I am trying to make a simple multithreading program that is just to learn the ideas behind it...
0
by: Anonymous | last post by:
Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <wfednQ6STZz2Z6faRVnytAA@bt.com> Lines: 15 X-Usenet-Provider: http://www.giganews.com...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.