473,395 Members | 1,341 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,395 software developers and data experts.

reusing a bit of code?

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
Nov 18 '05 #1
4 1247
The easierst way is to use an additional sub in your aspx file. But it's
necessary to identify all variables needed for the sub.
If there are some local variables that are needed for the sub it's
helpful to use Sub MySub(ByRef A As Interger) .... when calling the sub.

HTH
Steffen

Rob Meade schrieb:
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


Nov 18 '05 #2
Rob

Sounds like your a bit new to the concepts of Object Orientated Programming.
If your using Subs its probably VB.NET your programming in. Have a look at
the following article to get a hang of some of the concepts:
http://www.ondotnet.com/pub/a/dotnet...25/oop_vb.html

J

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:%2****************@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

Nov 18 '05 #3
Rob,
I would advice to make commonly used code in a dynamic-link
library(dll)(may be more than one depends on your needs)
using .NET and reference it in your pages.The advantage is that you can
reuse it for many applications.
The dll can contain multiple classes each has certain functions,procedures
etc. under a namespace.
Understand assemblies and namespaces to learn more on this.
Here is a link :

http://msdn.microsoft.com/library/de...assenamesp.asp

Hope this helps,
Marshal Antony
http://www.dotnetmarshal.com
For Eg
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:%2****************@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

Nov 18 '05 #4
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

Nov 18 '05 #5

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

Similar topics

2
by: Jo Voordeckers | last post by:
Hello all, I'm pretty new to the Java newsgroups so I apologize for dropping this into several maybe offtopic groups. I'm sorry! So on to my problem... I've come to a point in our RMI...
0
by: Oleg Paraschenko | last post by:
Hello, I'd like to introduce an article which might be of some interest: Reusing XML Processing Code in non-XML Applications HTML: http://uucode.com/texts/genxml/genxml.html PDF: ...
0
by: Mike | last post by:
Greetings, I have a COM+ component whose integrity I would like to maintain. In other words, I do not want to rebuild it in the .net environment. How do I go about reusing the DLL in a .net...
9
by: Alan | last post by:
Using VC++ (1998) compiler with PFE32 editor in Win2K Pro SP4. (DigitalMars CD on order. ) The program (below) instantiates a class and then deletes it. I would have thought that reusing the...
7
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename();...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
2
by: Andy Fish | last post by:
Hi, With languages like c# having namespaces, I was wondering what's the recommended practice for reusing source code. I'm not talking big stuff like log4net that's version controlled and...
3
by: Vik | last post by:
I use the same dataadapters and datasets on a few aspx pages. Currently I create these data controls on each page. Is it possible to create these controls only once and then use them on the...
7
by: Zodiac | last post by:
Hi all, I've been studying ASP.Net for a couple of weeks now.And it's starting to come to me. For me the next step is trying to figure out what is the best way to reuse code and webforms. For...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.