Global subroutines

  • Thread starter Thread starter tshad
  • Start date Start date
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.
 
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 :-)
 
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 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
 
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
 
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
 
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.
 
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
 
Back
Top