Re: Global Functions



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
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.
<snip>

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.



.