Accessing Classes RRS feed

  • Question

  • Hey

    probably a nuisance question:

    i have moved all of my code to relevant classes to offload some of the processing when the form starts as im getting render issues. I realise now (thanks to some advice) that the form needs as little code as possible . Some things like members and tables have been moved to respective cMembers & cTables classes and i call them like this

    in the form

    Dim gMembers as New cMembers

    now that i have instantiated gMembers as the New members collection, do i need to access this through the form Member gMembers or can i do something locally in another class that requires access like

    dim Gm as cMembers

    omitting the New(). Basically, Is this a way of hooking into a class instance that has already been instantiated or do i need to access it through the forms gMembers?

    The class members are populated by another class to hold data while the application is running and various methods require the data being held


    I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!

    Tuesday, June 30, 2020 6:27 AM

All replies

  • Hi,
    a good pattern for this case is singleton. Try following console demo:

    Module Module52
      Sub Main()
          Call (New C1).Execute()
          Call (New C2).Execute()
        Catch ex As Exception
        End Try
        Console.WriteLine("Continue enter key")
      End Sub
      Class C1
        Sub Execute()
          Dim GM = cMembers.GetCMembers
          GM.FirstMember = "initiate value"
        End Sub
      End Class
      Class C2
        Sub Execute()
          Dim GM = cMembers.GetCMembers
        End Sub
      End Class
      Class cMembers
        Private Shared _cMembers As cMembers
        Public Shared Function GetCMembers() As cMembers
          If _cMembers Is Nothing Then _cMembers = New cMembers
          Return _cMembers
        End Function
        Public Property FirstMember As String
      End Class
    End Module

    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Tuesday, June 30, 2020 7:33 AM
  • Thanks

    I will give that approach a look tonight


    I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!

    Tuesday, June 30, 2020 7:46 PM
  • Hi NachoShaw,

    How is the question going? Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, July 2, 2020 2:13 AM