Re: where to define variable for whoel application?
- From: "Mark Fitzpatrick" <markfitz@xxxxxxxxxx>
- Date: Mon, 19 Feb 2007 17:02:42 -0600
I'm not sure this is going to do what you think. Using it the way you
demonstrate would have all the pages in the application using the exact same
object. That's probably not good since you will run into issues where two
pages are performing actions on the same item at one time.
One of the things that you gain from re-writing it in each page that needs
it is the object is instantiated and destroyed within the context of that
page. That helps memory management so you don't have that same object being
held on to or created when it isn't needed. Does this function use any other
portions of an instantiated class, in other words does it need access to
methods or properties defined elsewhere in the class. For example, a
rectangle objects CalculateArea method would need access to the width and
length properties. If all you're doing is passing a value into the function
to perform an operation and get the value out, you may want, instead, to
create a shared function. This way the object isn't instantiated and all
your pages can essentially share a copy of the object since all they're
doing is passing their data in order to get it out.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"michel" <mm@mmm> wrote in message
news:%23CY1UXHVHHA.1212@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
i created a class 'test' with a method 'descrlimit()' (no matter).
That method is used in a lot of pages in the application, so i need to put
this code a lot of time: "Dim odescr As New test"
In order to avoid that, i wonder whether it would be possible to put that
line in a central place, like global.asax.
I tried this:
class file
--------
Public Class test
Public Function descrlimit(ByVal descr As Object) As String
Dim tmp As String = descr.ToString()
....
Return tmp
End Function
global.asax
-----------
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim odescr As New test
Application.Add("odescr", odescr)
End Sub
But it generates in all pages which use that method the error: "Name
'odescr' is not declared"
Thanks for helping
Michel
.
- Follow-Ups:
- Re: where to define variable for whoel application?
- From: michel
- Re: where to define variable for whoel application?
- From: Alexey Smirnov
- Re: where to define variable for whoel application?
- References:
- where to define variable for whoel application?
- From: michel
- where to define variable for whoel application?
- Prev by Date: Re: where to define variable for whoel application?
- Next by Date: Re: DataGrid Question
- Previous by thread: Re: where to define variable for whoel application?
- Next by thread: Re: where to define variable for whoel application?
- Index(es):
Relevant Pages
|