Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6669559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:09:51+00:00 2026-05-26T03:09:51+00:00

I have the following defined in my Form1: Dim Database As New DatabaseManager So

  • 0

I have the following defined in my “Form1”:

 Dim Database As New DatabaseManager

So that I can access all my database functions anywhere in the main form (database connection is initialized via the “private sub new()” function in the DatabaseManager class.

The works fine for all queries done in form1, however I have many other classes I’d like to be able to access the database from.

Does anyone know how to access the initiated class in my example? Since right now it is initiated in the main form, if I try to access any functions inside any other class functions it does nothing (doesn’t error out either).

I’m trying to figoure out how to dim a class one and I can access it from within any class and I can’t figure it out.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:09:52+00:00Added an answer on May 26, 2026 at 3:09 am

    One thing you could do is create a factory for the DatabaseManager and then just have all your other code call it from that factory. I’m very out of practice with VB syntax, but in C# it might look something like this:

    public class DatabaseManagerFactory
    {
        private static DatabaseManager _current = null;
    
        public static DatabaseManager Current
        {
            get
            {
                if (_current == null) _current = new DatabaseManager();
                return _current;
            }
        }
    }
    

    VB

    Public Class DatabaseManagerFactory
        Private Shared _current As DatabaseManager = Nothing
    
        Public Shared ReadOnly Property Current As DatabaseManager
            Get
                If _current Is Nothing null Then _current = New DatabaseManager()
                Return _current
            End Get
        End Property
     End Class
    

    The idea then is that anything in your application which needs to use a DatabaseManager would just call DatabaseManagerFactory.Current to get the one shared instance.

    Note that in this case DatabaseManager isn’t really a singleton, you can still instantiate one elsewhere in the application if you need to for some reason. If it should be an actual singleton then you’d want to make some modifications to the DatabaseManager class itself. Maybe give it a private constructor and implement this factory directly on the class? Something like this:

    public class DatabaseManager
    {
        private static DatabaseManager _current = null;
    
        public static DatabaseManager Current
        {
            get
            {
                if (_current == null) _current = new DatabaseManager();
                return _current;
            }
        }
    
        private DatabaseManager
        {
            // your initialization of the class
        }
    }
    

    VB

    Public Class DatabaseManager
        Private Shared _current DatabaseManager = Nothing
    
        Public Shared ReadOnly Property Current As DatabaseManager
            Get
                If _current Is Nothing Then _current = New DatabaseManager()
                Return _current
            End Get
        End Property 
    
        Private Sub New()
            ' your initialization of the class
        End Sub
    End Class
    

    (I encourage anybody more familiar with VB syntax to edit this answer accordingly to better address the question.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following members defined in a class that I'm trying to deserialise:
I have the following route defined routes.MapRoute( ItemName, {controller}/{action}/{projectName}/{name}, new { controller = Home,
I have the following defined in a file called build-dependencies.xml <?xml version=1.0 encoding=UTF-8?> <project
Disclaimer: absolute novice in Scala :( I have the following defined: def tryAndReport(body: Unit)
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
I have the following rule defined in the .htaccess file of my webapplication's root
I have the following function defined inside my linked list class. The declaration in
I have the following layout defined for one of my Activities: <?xml version=1.0 encoding=utf-8?>
I have been following the ExtDirectSpring form posting guide closely. I defined an api

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.