Consulting

Results 1 to 3 of 3

Thread: Hierarchical class module wrapper code

  1. #1

    Hierarchical class module wrapper code

    I haven't been able to write the kind of code I'd like to using VBA. It's really all I program in, so I don't know for sure what it's actually missing, but the closes thing I've found is inheritance in .Net.

    I'd like to have a class module for selected objects in the application's (in this case MS Project) object hierarchy that contains properties and methods for the types of things my company would like to do with Project. One example is updating actual hours worked for each resource within each task within each project. What I'm having trouble with is making an instance of each class module represent an actual instance of the same object in Project AND having my own class modules relate to each other in a hierarchy the same way Project's own objects do.

    I've been able to make the instance of each class module represent it's counterpart in Project through the standard module code like this:
    Dim myProject As New cProject
    For Each Task in myProject.Project
    The Project property in class cProject being:
    Property Get Project() As MSProject.Project    Set Project = mpjProject
    End Property
    where mpjProject is just the private internal class variable, also of type MSProject.Project. I have an Open method in cProject, which sets mpjProject to an actual open project so that myProject.Project (can't seem to set the default property with Attribute DefaultMember.VB_UserMemId = 0 when that property is an object) represents an actual project. The problem comes along when I try to say:

    For Each myTask In myProject.Project.Tasks
    where myTask is an instance of cTask, which like cProject, has a Task property of type MSProject.Task. I want myTask to represent the first Task in the actual Project, but to extend that task object with my own cTask module. So like I was able to do with Project above, my custom methods in cTask could be called from myTask, or the MS Project methods could be called from myTask.Task.

    To summarize, I want 1) a hierarchy of objects that 2) extend the application's built in objects. Is there a way to do this, or is the language limited in this way?

  2. #2
    Moderator VBAX Wizard SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    6,900
    Location
    One example is updating actual hours worked for each resource within each task within each project
    With Task.Resource
    A = .ActualWork
    With .Assignment
    .ActualWork = .ActualWork + 120 'Minutes
    End With
    B = .ActualWork
    End With
    B = A + 120 = True



    Do you realize that inheritance to work, you must duplicate the entire MS Project object model even though most of the object classes will merely have one Object variable, set by reference?

    Have you considered creating an abbreviated custom Object Model to run parallel with the Application and have your main code refer to either as needed.

    For each Tsk in Tasks
       For Each Res in Tsk.Resources
         MyVariable = Custom.Tasks(Tsk,Name).Resources(Res.Name).CustomProperty
         HoursWorked = Res.ActualHours 'Application property
       Next
    Next
    Attached Files Attached Files
    Last edited by SamT; 09-18-2015 at 07:15 PM.
    Please take the time to read the Forum FAQ

  3. #3
    Quote Originally Posted by tbaker818 View Post
    I haven't been able to write the kind of code I'd like to using VBA. It's really all I program in, so I don't know for sure what it's actually missing, but the closes thing I've found is inheritance in .Net.

    I'd like to have a class module for selected objects in the application's (in this case MS Project) object hierarchy that contains properties and methods for the types of things my company would like to do with Project. One example is updating actual hours worked for each resource within each task within each project. What I'm having trouble with is making an instance of each class module represent an actual instance of the same object in Project AND having my own class modules relate to each other in a hierarchy the same way Project's own objects do.

    I've been able to make the instance of each class module represent it's counterpart in Project through the standard module code like this:
    Dim myProject As New cProject
    For Each Task in myProject.Project
    The Project property in class cProject being:
    Property Get Project() As MSProject.Project    Set Project = mpjProject
    End Property
    where mpjProject is just the private internal class variable, also of type MSProject.Project. I have an Open method in cProject, which sets mpjProject to an actual open project so that myProject.Project (can't seem to set the default property with Attribute DefaultMember.VB_UserMemId = 0 when that property is an object) represents an actual project. The problem comes along when I try to say:

    For Each myTask In myProject.Project.Tasks
    where myTask is an instance of cTask, which like cProject, has a Task property of type MSProject.Task. I want myTask to represent the first Task in the actual Project, but to extend that task object with my own cTask module. So like I was able to do with Project above, my custom methods in cTask could be called from myTask, or the MS Project methods could be called from myTask.Task.

    To summarize, I want 1) a hierarchy of objects that 2) extend the application's built in objects. Is there a way to do this, or is the language limited in this way?

    your problem is very confusing and what you did is something that only an expert like you can understand. i haven't worked on that before but looking forward to make that one a try too. hope you'll find a solution.

Posting Permissions

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