Module Startup Public oApplication As New AppObject Public Sub Main() oApplication.StartApp() End Sub End ModuleAnd the application class. None of the objects created before the sub are visible anywhere else except in this class.
Imports System.Data Imports System.Data.SqlClient Public Class AppObject ' DLLs Public oGenProcs As New DotNetGenProcs.DotNetGenProcs Public oSQLStuff As New SQLStuff.GetSQLConnString ' Properties Public sConnString As String ' Solution level objects Public oMenu As New AppMenu ' Menu class Public oToolbars As New AppToolbars ' Toolbar class Public oForm As New frmApplication ' Application form Public Sub StartApp() 'Load DLL's used in this application LoadDLLs() ' Set up the SQL connection string SetupConnString() ' Load the menu from the menu class oMenu.LoadMenu(oForm) ' Show the toolbars here oToolbars.LoadToolbars(oForm) ' Set up the background form SetupGUI(oForm) ' Display the application form Application.Run(oForm) End Sub Private Sub SetupGUI(ByVal oForm As frmApplication) End Sub Private Sub LoadDLLs() ' General procedures library Dim _oGenProcs As DotNetGenProcs.DotNetGenProcs oGenProcs = _oGenProcs End Sub Private Sub SetupConnString() '************************************************************ ' Use the SQLStuff DLL to create a SQL Connection string '************************************************************ With oSQLStuff .sDataSource = "(local)" .sInitialCatalog = "Northwind" .sUserId = "someone" .sPassword = "password sConnString = .sConnString End With End Sub Public Function OpenConnection() As SqlConnection ' Set up the return value Dim oRetVal As SqlConnection oRetVal = Nothing ' Create the connection Dim oConnection = New SqlConnection(Me.sConnString) oConnection.Open() ' If the connectin was opened, set the return value ' to to the connection, otherwise set it to Nothing. If oConnection.State = ConnectionState.Open Then oRetVal = oConnection Else oRetVal = Nothing End If ' Return the return value OpenConnection = oRetVal End Function End Class