CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    [RESOLVED] VB 6.0 Object Reference

    Hello all, this is my first post on CodeGuru.

    I am currently developing an ActiveX exe using VB 6.0. My plan calls for a private class (clsJournalBase) to be delcared and instanced once through sub Main() when the first exportable object is created.

    I have two classes (clsJournal and clsJournalMaster both GlobalMultiUse) that can be exported through this exe; I am trying to get each object exported to create a reference to the single instance of clsJournalBase in the main module in order to have the exported objects react to events raised from clsJournalBase.

    I know I cannot use the GetObject() function since I have created these classes in VB; and when I try to create my own function to pass the reference (written as a public function in main module), it creates a new instance in the two exported classes.

    Is there a way to pass a reference back with out using GetObject()?

    Any help would be appreciated. If some one has already posted a similar situation, please let me know or link to it.

    Thank you in advance.

  2. #2
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: VB 6.0 Object Reference

    Or is there another way to access the messages from clsJournalBase in my two exportable classes that will allow me to avoid setting up a property in each class as type clsJournalBase?

    Finally, the ActiveX exe is going to be stored and run on a network server (Windows 2003 Small Business) while the client apps are run on client machines (Win XP SP2); I have tested event firing across the network and it has performed fine, I am just unsure if this would add any more complication to the structuring of my classes.

    Here is a simplified version of the code.

    clsJournalBase's code is really not important to this problem. Just keep in mind that the class contains events. Also keep in mind that the start up object is Sub Main().

    Main Module
    Code:
    Private JournalBase as clsJournalBase
    
    Public Sub Main()
        set JournalBase = New clsJournalBase
    End Sub
    
    Public Function GetJournalBase() as clsJournalBase
        set GetJournalBase = JournalBase
    End Function
    clsJournalMaster and clsJournal both have the following constructs.
    Code:
    Private WithEvents m_objJournalBase as clsJournalBase
    
    Private Sub Class_Initialize()
        set m_objJournalBase = MainModule.GetJournalBase()
    End Sub
    
    'Event Handlers for events raised in clsJournalBase.
    Of course each of the classes has more code that does the actual processing for its tasks; this is the relavant code for how I reference the classes.
    Last edited by VehementSoftware; July 25th, 2008 at 01:24 PM. Reason: Adding Coding Example

  3. #3
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: VB 6.0 Object Reference

    Okay, apparently I am trying to create a Singleton Object. After doing some research, I have ordered a book "Advanced Visual Basic 6" and will post if the solutions work.

    If anyone has any opinions about singletons, I'd love to hear them.

  4. #4
    Join Date
    Aug 2005
    Location
    Imperial College London, England
    Posts
    490

    Re: VB 6.0 Object Reference

    Why? I've never seen a purpose for them in a language that doesn't support inheritance. They might have a purpose in .NET, but VB6?
    Help from me is always guaranteed!*
    VB.NET code is made up on the spot with VS2008 Professional with .NET 3.5. Everything else is just made up on the spot.
    Please Remember to rate posts, use code tags, send me money and all the other things listed in the "Before you post" posts.

    *Guarantee may not be honoured.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VB 6.0 Object Reference

    Ever think of searching for it? I found the article that i was thinking of in a few seconds.

    http://www.vbforums.com/showthread.php?t=310205
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: VB 6.0 Object Reference

    The base class needs to modify system wide globally unique data. If there is a better way to do that, then I would love to hear it. This has been frustrating beyond all end.

  7. #7
    Join Date
    Jul 2008
    Location
    Appleton, WI
    Posts
    23

    Re: VB 6.0 Object Reference

    Sorry dglienna, I just found out what the technique is called today. Had I known I would not have posted a thread; and since the thread was already started, I thought I would mention that I found the book.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured