Modules

A

Alexia

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
 
A

Armin Zingler

Alexia said:
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
 
A

Alexia

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??
 
S

solex

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
 
A

Armin Zingler

Alexia said:
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?
 
A

Alexia

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.

--------------------------------------------
 
A

Armin Zingler

Alexia said:
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-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 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.
 
A

Alexia

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. :blush:)
 
A

Armin Zingler

Alexia said:
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. :blush:)


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top