How to make a class accessible globally

Good day,

I have a class that handles reading recipes from a database, allows the values to be changed and re-saved, and does some validation. I would like that class to be accessible globally in my application. I am struggling with the best way to do it. I have some ideas, but I wonder if there is a better way.

1. Create a module, instantiate the class once inside the module and access it that way.

2. Use all shared variables within the class.

3. Pass a reference to the class through properties, to all my applications forms and classes.

As a follow up question, how is a "Module" different than a class When I go to "Add new item" and choose module or class, what is the difference. The only thing that I have been able to determine is that a module seems to be accessible globally.

Thanks,




Answer this question

How to make a class accessible globally

  • cgodoy

    That is exactly what I needed to know.

    Thank you.



  • coderkidd

    Both 1 and 3 would work just fine, I'm a little unsure about how 2 would work.

    Modules existed in VB in the pre .net era and are often assumed to be a dated concept when looking at the OO approach.

    Modules in VB.NET are indeed object-oriented. The VB.NET compiles a module as a class with a private constructor and sets all of the methods and fields to be shared. So you can achieve the same effect by creating a class with all shared methods and fields but obviously that involves more coding.

    Shared methods dont need to instantiate an instance of the class to be used.

    Module Foo
    Sub Bar

    End Sub
    End Module

    equates to

    Class Foo
    Shared Sub Bar
    End Sub
    End Class

    Personally I'd use a module.


  • How to make a class accessible globally