Hi Rob,
It's good that you are noticing repeated code, and thinking that you should
make it available in one location for optimal performance and
maintainability of your app. That is just good sense, and is, in fact, one
of the principal considerations that resulted in Object-oriented programming
concepts.
In procedural programming, you use Subs and Functions in Function libraries
(or DLLS) for this purpose. Object-Oriented programming extends the idea of
re-usable code with the idea of reusable classes. The classes contain data
as well as Functions and Subs (which are called "Methods" in OOP). A class
is basically a structure containing both data (n the form of fields and
properties) and executable code in the form of Functions and Subs (Methods).
A field is like a global variable in that it is simply a variable with the
additional attribute of accessibility (encapsulation). Accessibility is how
accessible the variable is. Public fields/properties/methods are accessible
to anything. Private fields/properties/methods are accessible only within
the given class. Protected are accessible by any class which inherits the
given class. Etc. Properties are actually Methods, but appear much like
Fields in terms of accessing them. However, since the Property has a get and
set method, other processing can be done when getting or setting the value
of the Property.
You really should read up on OOP principles at some point to become more
familiar with how to use them. In the meantime, however, I would advise you
to create a class library (project) of functions (Methods) that you want to
use in multiple pages.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:#Z**************@TK2MSFTNGP12.phx.gbl...
Hi all,
I'm in the middle of finishing a page and I've noticed that I have a chunk
of code that is used in two places - its exactly the same - I guess I can
rip this out - save it seperately and then call it into both areas when
needed - is this a 'class' - I'm not fully up with all the terminology...
So what should I do - within the same page create a sub and put it in
there then call it - or save it to a different type of file (somone indicate
which one?) and then reference it somehow to use it?
Any help would be appreciated,
Regards
Rob