Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Unanswered: Nested class modules, howto?

    Hullo folks,

    I've been trying to find a way to encapsulate all of my subordinate objects in the same class module instead of having to provide them both. Access gets mad at me if i try to declare Public/Private Class inside the module...

    Basically I want to do something like this, which is similar to the rather sparse documentation I've been able to track down:

    Public Class myMainClass
    Public Class mySubordinateClass
    'properties and such
    End Class

    'other properties for main class go here
    End Class
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by Teddy
    Hullo folks,

    I've been trying to find a way to encapsulate all of my subordinate objects in the same class module instead of having to provide them both. Access gets mad at me if i try to declare Public/Private Class inside the module...

    Basically I want to do something like this, which is similar to the rather sparse documentation I've been able to track down:

    Public Class myMainClass
    Public Class mySubordinateClass
    'properties and such
    End Class

    'other properties for main class go here
    End Class
    Ted,

    Trying to do inheritance in VB???? Um ... I don't think so ... I got a VB Developer's handbook and it says that implementation inheritance doesn't exists for VBA ...

    It says that you have interface inheritance by using the Implements keyword in the class module declaration section ...
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Not quite, I'm not trying to extend my objects, I'm trying to stuff them into other objects. The subordinate class does not inherit any of the properties of the main class, in fact it IS a property of the main class. Right now it works just fine so long as I keep the classes seperate and manually instantiate my subordinates in the main class. Ie:

    Here's a sample "subordinate" class, which will be used as a property later:
    Code:
    clsSubordinateClass:
    --------------
    private m_var1
    private m_var2
    
    Public Property Get Var1() As String
       Var1 = m_var1
    End Property
    
    Public Property Let Var1(strIn As String)
       m_var1 = strIn
    End Property
    
    Public Property Get Var2() As string
       Var2 = m_var2
    End Property
    
    Public Sub CopyVars(0
       m_var2 = m_var1
    End Sub
    So that basically we have an object called clsSubordinateClass that has to properties (var1 and var2), and a method called CopyVars that makes var2 = var1.

    Now I want to stuff that into a "main" class as a property:
    Code:
    clsMainClass
    --------------
    
    Public SubClass As New clsSubordinateClass
    Public m_active As Boolean
    
    Public Property Get Active() As Boolean
       Active = m_active
    End property
    
    'whole bunch more properties and methods go here
    That's what I currently have setup. It works. I can call things like:

    Code:
    dim MainClass As clsMainClass
    
    Set MainClass = New clsMainClass
    
    If MainClass.Active = -1 Then
       With MainClass.SubClass
          .var1 = "test"
          .Copy
       End With
    End If
    That's perfect, exactly how I want it to act. Now the question is how/can the subordinate class be written all in one shot instead of needing to be an entirely different class module. Ie:

    Code:
    clsMainClass
    ------------------
    
    Public m_active As Boolean
    
       Private Class SubClass
         private m_var1
         private m_var2
    
         Public Property Get Var1() As String
            Var1 = m_var1
         End Property
    
         Public Property Let Var1(strIn As String)
            m_var1 = strIn
         End Property
    
         Public Property Get Var2() As string
            Var2 = m_var2
         End Property
    
         Public Sub CopyVars(0
            m_var2 = m_var1
         End Sub
       End Class
    
    Public Property Get Active() As Boolean
       Active = m_active
    End property
    
    'whole bunch more properties and methods go here
    A bit long winded I know, but hopefully that clears up my intent?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Ted

    I thought this looked interesting so had a gander on t'internet. Did you pick this up from http://msdn.microsoft.com/library/de...components.asp?

    If so, this is VB.NET. I can't find anything in VBA or VB that supports it. I think the Class keyword is specific to (VB).NET. You probably know this to a greater level of detail but anyway - classic VB hides a lot of the declarations from us developers. Great when you are starting out but a pain when you want to start doing advanced stuff. Have you used .NET? Have you seen all the code the IDE creates for you when you pop a form into your project? All that code is generated in classic VB but hidden from the developer. I would bet my bottom dollar the same is true of the Class keyword - this is created behind the scenes in a class module definition but it means you can't directly specify a class. I really strongly suspect that you are bound to 1 Class Module = 1 Class and vice versa.

    EDIT - I also checked out VB6 and the same issue - Class is unrecognised.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Mar 2005
    Posts
    261
    Code:
    I really strongly suspect that you are bound to 1 Class Module = 1 Class and vice versa.
    This is correct. A 'Class Module' is essentially the definition of a class in VB6/VBA.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    <OT>

    Hi Wayne
    Nice to see you again - I think it takes a difficult question to pique your interest. I referred to you in this thread - you had any luck with that MDE interpreter?
    </OT>
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Mar 2005
    Posts
    261
    Quote Originally Posted by pootle flump
    <OT>

    Hi Wayne
    Nice to see you again - I think it takes a difficult question to pique your interest. I referred to you in this thread - you had any luck with that MDE interpreter?
    </OT>
    Hi Pootle, it's a case of finding the time to participate to discussions at the moment(!), so it tends to be the not-so-common questions that I get involved in. As for the MDE "interpreter", see here: MDE Conversion Service - of course only for legit purposes.

  8. #8
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Thanks for taking a look guys. I received similar feedback from a few other sources as well. Unfortunately the common concensus says I simply can't distribute all of my dependent classes as a single object.

    I decided to take a little different route and created a stand-alone "class management" utility that acts as a central repository for my most current objects and allows "installation" of modules (and more importantly, their dependent modules) to any given mdb. It's not my preferred method, but it seems to work.

    Any other nifty methods for distributing interdependent classes to other developers would certainly be much appreciated...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by Teddy
    Any other nifty methods for distributing interdependent classes to other developers would certainly be much appreciated...
    Compile a DLL? They're implimentation independent
    Testimonial:
    pootle flump
    ur codings are working excelent.

  10. #10
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by Teddy
    Thanks for taking a look guys.
    My pleasure - I always like yours, Mike's and Izy's threads - I always know they will be a bit different
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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