By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

Modules

P: n/a
Hi,

I just wanted a hand on using modules. I have just
managed to create a custom smooth progress bar control
and i wanted to know if it is possible to insert the code
in a module so it can be called from any of my forms.
what i am confused on is the syntax i have to use in the
module. here is my code i will need to reuse for each
onclick event throughout my appliaction:

Me.SmoothProgressBar1.Value = 100
Me.SmoothProgressBar2.Value = 0

Me.Timer1.Interval = 1
Me.Timer1.Enabled = True

i also have to add code for the tick event for each timer
i place on the forms that use the PBar. here is the code
for that:

If (Me.SmoothProgressBar1.Value > 0) Then
Me.SmoothProgressBar1.Value -= 1
Me.SmoothProgressBar2.Value += 1
Else
Me.Timer1.Enabled = False
End If

Can anyone help me with what i need to write in my
module? and what code i need to call this for eac onclick
event.

Im new to all this and would appreciate any help
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Alexia" <an*******@discussions.microsoft.com> schrieb
I just wanted a hand on using modules. I have just
managed to create a custom smooth progress bar control
and i wanted to know if it is possible to insert the code
in a module so it can be called from any of my forms.
what i am confused on is the syntax i have to use in the
module. here is my code i will need to reuse for each
onclick event throughout my appliaction:


Why do you want to use a Module? A control is a class directly or indirectly
inherited from System.Windows.Forms.Control:

Class MyControl
Inherits Controls

'...
End Class

To add the control to a Form, execute the following code within the Form:

dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2

P: n/a
Im not sure on what the best approach was. I was told to
use a module by my friend.
All i want to achieve is to wright the code i stated
below in one place so i dont have to keep re-writing it
througout my application.
What is the best approach to achieve this??
-----Original Message-----
"Alexia" <an*******@discussions.microsoft.com> schrieb
I just wanted a hand on using modules. I have just
managed to create a custom smooth progress bar control
and i wanted to know if it is possible to insert the code in a module so it can be called from any of my forms.
what i am confused on is the syntax i have to use in the module. here is my code i will need to reuse for each
onclick event throughout my appliaction:
Why do you want to use a Module? A control is a class

directly or indirectlyinherited from System.Windows.Forms.Control:

Class MyControl
Inherits Controls

'...
End Class

To add the control to a Form, execute the following code within the Form:
dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

.

Nov 20 '05 #3

P: n/a
Alexia,

What Armin is saying is that once you put the code in your control it will
"go along" with the control every time you drag and drop it on a form.
There is no need to separate out the code in to a module.

Dan


"Armin Zingler" <az*******@freenet.de> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
"Alexia" <an*******@discussions.microsoft.com> schrieb
I just wanted a hand on using modules. I have just
managed to create a custom smooth progress bar control
and i wanted to know if it is possible to insert the code
in a module so it can be called from any of my forms.
what i am confused on is the syntax i have to use in the
module. here is my code i will need to reuse for each
onclick event throughout my appliaction:
Why do you want to use a Module? A control is a class directly or

indirectly inherited from System.Windows.Forms.Control:

Class MyControl
Inherits Controls

'...
End Class

To add the control to a Form, execute the following code within the Form:

dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #4

P: n/a
"Alexia" <an*******@discussions.microsoft.com> schrieb
Im not sure on what the best approach was. I was told to
use a module by my friend.
All i want to achieve is to wright the code i stated
below in one place so i dont have to keep re-writing it
througout my application.
What is the best approach to achieve this??

I read it several times now, but I still don't get it. (it's 00:45 AM here
;-)

Is the code you posted the event handler for OnClick of the progressbar? Why
do you use two Progressbars? Is the Timer part of the Progressbar and does
it always exist for each progressbar?

Could you please describe the circumstances once again?
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html
Nov 20 '05 #5

P: n/a
Hi Armin,

the code i have posted is part of the onclick event for a
button that starts the progress bar. The timer is also a
part of the progress bar as this is a custom built
control. The timer always exists for every proress bar.

There shoulkd only be one progress bar in that code i gave.

any further advise u can give?? the code u gave me....
where do i write this?? i tried to copy and paste it into
my code window but it didnt seem to like it. Could u plz
explain what it is doin? sorry, im a real beginner to all
this.

--------------------------------------------

I read it several times now, but I still don't get it. (it's 00:45 AM here;-)

Is the code you posted the event handler for OnClick of the progressbar? Whydo you use two Progressbars? Is the Timer part of the Progressbar and doesit always exist for each progressbar?

Could you please describe the circumstances once again?
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html
.

Nov 20 '05 #6

P: n/a
"Alexia" <an*******@discussions.microsoft.com> schrieb
the code i have posted is part of the onclick event for a
button that starts the progress bar. The timer is also a
part of the progress bar as this is a custom built
control. The timer always exists for every proress bar.

There shoulkd only be one progress bar in that code i gave.

any further advise u can give?? the code u gave me....
where do i write this?? i tried to copy and paste it into
my code window but it didnt seem to like it. Could u plz
explain what it is doin? sorry, im a real beginner to all
this.


No problem, we were all beginners. :-)

You wrote: "I have just managed to create a custom smooth progress bar
control". That's why I assumed that you've already created your own class
that is directly or inderectly derived from System.Windows.Forms.Control.
The class System.Windows.Forms.Control is the base class for all controls.
Labels, Textboxes and so on are all derived from the Control class.

How to create your own controls:
http://msdn.microsoft.com/library/en...mscontrols.asp

About OOP, especially the sub topic "Inheritance":
http://msdn.microsoft.com/library/en...ithObjects.asp
These are two progress bars:
Me.SmoothProgressBar1.Value = 100
Me.SmoothProgressBar2.Value = 0
What is the type of SmoothProgressBar1 and SmoothProgressBar2? Didn't you
create them on your own?
The code I gave you is the base structure of a class. It is usually in a
separate file. Where did you paste the code?

The following lines
dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form

can be pasted in the Load event of the Form or in the constructor. The
constructor is Sub New in the "Windows Forms Designer generated code"
region. After calling InitializeComponents, the code can be executed. You
can also put it in a sub outside the constructor and call it in the
constructor to avoid opening the region every time you want to add code to
the constructor. Example:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated Code "

Public Sub New()
MyBase.New()

InitializeComponent()

MyNew
End Sub
'.....
#end region

private Sub MyNew
dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form
end sub

'......
End Class
I hope this helps because I still didn't fully understand the structure of
your current project. Please ask again if something's not clear.

--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #7

P: n/a
Thx for your help Armin,

As you probably guessed, i didnt write the controls on my
own. I was directed to a website that had all the code and
instructions so i am not to sure on how it all works. I
got the code from:

http://support.microsoft.com/default.aspx?scid=kb;EN-
US;Q323088

I pasted the code into the form load event but it didnt
like it for some reason. Im about to leave work now so i
will try again when i get home. I will let u know about
the outcome.
Thx again for your help. :o)

-----Original Message-----
"Alexia" <an*******@discussions.microsoft.com> schrieb
the code i have posted is part of the onclick event for a button that starts the progress bar. The timer is also a
part of the progress bar as this is a custom built
control. The timer always exists for every proress bar.

There shoulkd only be one progress bar in that code i gave.
any further advise u can give?? the code u gave me....
where do i write this?? i tried to copy and paste it into my code window but it didnt seem to like it. Could u plz
explain what it is doin? sorry, im a real beginner to all this.
No problem, we were all beginners. :-)

You wrote: "I have just managed to create a custom smooth

progress barcontrol". That's why I assumed that you've already created your own classthat is directly or inderectly derived from System.Windows.Forms.Control.The class System.Windows.Forms.Control is the base class for all controls.Labels, Textboxes and so on are all derived from the Control class.
How to create your own controls:
http://msdn.microsoft.com/library/en- us/cpguide/html/cpconcreatingwinformscontrols.asp
About OOP, especially the sub topic "Inheritance":
http://msdn.microsoft.com/library/en- us/vbcn7/html/vbconProgrammingWithObjects.asp

These are two progress bars:
Me.SmoothProgressBar1.Value = 100
Me.SmoothProgressBar2.Value = 0
What is the type of SmoothProgressBar1 and SmoothProgressBar2? Didn't youcreate them on your own?
The code I gave you is the base structure of a class. It is usually in aseparate file. Where did you paste the code?

The following lines
dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form

can be pasted in the Load event of the Form or in the constructor. Theconstructor is Sub New in the "Windows Forms Designer generated code"region. After calling InitializeComponents, the code can be executed. Youcan also put it in a sub outside the constructor and call it in theconstructor to avoid opening the region every time you want to add code tothe constructor. Example:

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated Code "

Public Sub New()
MyBase.New()

InitializeComponent()

MyNew
End Sub
'.....
#end region

private Sub MyNew
dim c as mycontrol

c = New MyControl 'creates the control
Me.Controls.Add(c) 'adds it to the Form
end sub

'......
End Class
I hope this helps because I still didn't fully understand the structure ofyour current project. Please ask again if something's not clear.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

.

Nov 20 '05 #8

P: n/a
"Alexia" <an*******@discussions.microsoft.com> schrieb
Thx for your help Armin,

As you probably guessed, i didnt write the controls on my
own. I was directed to a website that had all the code and
instructions so i am not to sure on how it all works. I
got the code from:

http://support.microsoft.com/default.aspx?scid=kb;EN-
US;Q323088

I pasted the code into the form load event but it didnt
like it for some reason. Im about to leave work now so i
will try again when i get home. I will let u know about
the outcome.
Thx again for your help. :o)

Didn't you follow the steps described in the mentioned site? I can not
describe it better. :-)
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.