Re: Global Functions
- From: "Tom Leylan" <tleylan@xxxxxxxxxx>
- Date: Fri, 15 Dec 2006 20:53:41 -0500
Anil: Yes you can read it right here :-) Never use a module!
VB.Net is an object-oriented language and by definition that should lead to
object-oriented solutions. If there is no OOP solution (and that would seem
unlikely given apps written in SmallTalk, C++, Java, C# and all the other
OOP-based languages) then one might find themselves forced into having to
resort to a "hack". Take my word for it don't start with the "hack" or you
will never stop applying hacks. People will stare at your code and giggle
behind your back...
What you are describing isn't a "module" you are describing a Singleton
Class. If you want to read something perhaps about the Singleton Class
would be a good start.
Try it you may like it.
"Anil Gupte" <anil-list@xxxxxxxxxxx> wrote in message
news:OCFPtkBIHHA.3676@xxxxxxxxxxxxxxxxxxxxxxx
Thanx, that will get me started. Do you happen to know any place where I
can read more about when to use a Module and when to use a class?
Thanx again,
--
Anil Gupte
www.keeninc.net
www.icinema.com
"Branco Medeiros" <branco.medeiros@xxxxxxxxx> wrote in message
news:1166131605.256508.207250@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Anil Gupte wrote:
I am trying to set up a function that connects to the database that I
can
then use gloablly. I set up a class called L3Global in which I have a
function as follows:
Public Function SetDBConnect()<snip>
Now I want to use this is all my forms (MDI). I set up<snip>
Public L3G As New L3Global
and then under the approporate button click I have:
Dim ConnL3Producer As New OleDbConnection
ConnL3Producer = L3G.SetDBConnect
The problem is, do I have to setup an instance of L3Global in each form?
That defeats the purpose, because each one opens a new connection. How
can
I use this connection object in all my forms but open it only once?
Ideally
I would like to move as much of the intialization (creating the
OLEDBAdapter
etc) to the global routine.
I guess you can declare a Module, instead of a class:
<aircode>
Module L3Global
Private mConnection As OleDBConnection
Public Function ConnectDB() As OleDBConnection
If mConnection Is Nothing Then
Dim ConText As String = "Your connection string"
mCOnnection = New OleDBConnectins(ConText)
End If
Return mConnection
End Function
End Module
</aircode>
And then, in your Forms you'd have:
Dim ConnL3Producer _
As OleDbConnection = L3Global.ConnectDB()
Improvise over that.
Regards,
Branco.
.
- Follow-Ups:
- Re: Global Functions
- From: Branco Medeiros
- Re: Global Functions
- From: Cor Ligthert [MVP]
- Re: Global Functions
- From: Dennis
- Re: Global Functions
- References:
- Global Functions
- From: Anil Gupte
- Re: Global Functions
- From: Branco Medeiros
- Re: Global Functions
- From: Anil Gupte
- Global Functions
- Prev by Date: SP1 Install - was it successful?
- Next by Date: Re: hey children - lets all re-learn every 2 years
- Previous by thread: Re: Global Functions
- Next by thread: Re: Global Functions
- Index(es):