Global subroutines

T

tshad

Is there a way to set up global subs and functions?

I just want to put some functions (such as bittest, bitclear, bitset - I
know there are already bitarray functions) that all my screens can access
directly without setting up includes or controls. I know that you can put
global variable ( for application and sessions) and code to manipulate them
in the global.asax file, but what about functions?

Thanks,

Tom.
 
S

Stefan Kiryazov

No, there is no way to do this. You can do any of the following:

- Define a public class with static members - you can call them
anywhere you like
- Define a base class, deriving from System.Web.UI.Page and implement
all globally needed suborutines in it as protected methods. Then, you
inherit all your pages in the project from this base class, so the
members defined in the base class are available throughout the project.
Hope this helps :)
 
T

tshad

Stefan Kiryazov said:
No, there is no way to do this. You can do any of the following:

- Define a public class with static members - you can call them
anywhere you like
- Define a base class, deriving from System.Web.UI.Page and implement
all globally needed suborutines in it as protected methods. Then, you
inherit all your pages in the project from this base class, so the
members defined in the base class are available throughout the project.
Hope this helps :)

I knew I could do this

I was hoping I could just set up a function in a standard area that I didn't
have to define on each page to handle generic functions that I may or may
not call on different pages.

I also am not using code behind at the moment or compiling my code.

Thanks,

Tom
 
I

IPGrunt

I knew I could do this

I was hoping I could just set up a function in a standard area that I didn't
have to define on each page to handle generic functions that I may or may
not call on different pages.

I also am not using code behind at the moment or compiling my code.

Thanks,

Tom

Then use the static function. For example, create a Util.cs class file.

Then declare each function in Util as a method.

public static bool bitTest (sometype somevar)
{
bool somthing;

// add code

return somthing;
}


then you call bitTest in another class as:

bool result = Util.bitTest (myVar);


Get it?

-- ipgrunt
 
T

tshad

IPGrunt said:
Then use the static function. For example, create a Util.cs class file.

Then declare each function in Util as a method.

public static bool bitTest (sometype somevar)
{
bool somthing;

// add code

return somthing;
}


then you call bitTest in another class as:

bool result = Util.bitTest (myVar);


Get it?

That sounds pretty good.

How do I set it up?

Does it need to be compiled?

Where does it go (in the Root folder)?

Tom
 
I

IPGrunt

That sounds pretty good.

How do I set it up?

Does it need to be compiled?

Where does it go (in the Root folder)?

Tom

Of course you need to compile -- everything in .net is managed code.

Using a C# project in VS.NET:

1. Add a new Class to your project.
2. Name it Util.cs (or whatever you like).
3. In Util.cs enter the static methods as described above.

You can then invoke (call) them in any of your project's cs files as:

returnvalue = Util.yourMethod (some, args);

without having to first instantiate your class. That's the beauty of
using static classes.

Note: Use static classes sparingly. You don't want all your classes to be
static.

good luck,

-- ipgrunt
 
T

tshad

IPGrunt said:
Of course you need to compile -- everything in .net is managed code.

Using a C# project in VS.NET:

My problem is I don't have Visual Studio to build it. I use Dreamweaver for
my pages and I have been doing all my pages with setting up code behind
pages and have all my code on the same page as the design objects.
 
I

IPGrunt

My problem is I don't have Visual Studio to build it. I use Dreamweaver for
my pages and I have been doing all my pages with setting up code behind
pages and have all my code on the same page as the design objects.

Maybe time to change? Have you looked at the free developer tool? WebMatrix
or something like that.

-- ipgrunt
 

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


Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top