none
Task Parameter RRS feed

  • Question

  • Hi,

    I have the following code -

    Public Sub Proc1()
        Dim vTask As Task
        For Each vTask In ActiveSelection.Tasks
            If vTask Is Nothing Then GoTo NextTask
            Debug.Print vTask.ID; vTask.Name; vTask.Predecessors; vTask.Successors
            Proc2 (vTask)
    NextTask:
        Next vTask
    End Sub
    Public Sub Proc2(pTask As Task)
        Dim vTask As Task
        For Each vTask In pTask.OutlineChildren
            Debug.Print vTask.ID, vTask.Name, vTask.Predecessors, vTask.Successors
        Next vTask
    End Sub

    I simplified the program so there might be some syntax issue.  But the point is I received error on "Proc2 (vTask)" in Proc1: "Comiple error: Type mismatch."  If I merge Proc2 into Proc1, it shows next level tasks, but I want to make a recursive call so Proc2 has to be a separate one.

    Can anyone give me a hint what happened?  Thanks.


    AndreT from MS Project Customization and Programming Forum
    Wednesday, August 17, 2011 1:08 AM

Answers

  • The ( ) around (vtask) is the problem. I would write the code as:

    Public Sub Proc1()
        Dim vTask As Task
        For Each vTask In ActiveSelection.Tasks
            If Not vTask Is Nothing Then
                Debug.Print vTask.ID; vTask.Name; vTask.Predecessors; vTask.Successors
                If vTask.Summary Then
                    Proc2 vTask
                End If
            End If
        Next vTask
    End Sub
    Public Sub Proc2(pTask As Task)
        Dim vTask As Task
        For Each vTask In pTask.OutlineChildren
            Debug.Print vTask.ID, vTask.Name, vTask.Predecessors, vTask.Successors
        Next vTask
    End Sub

    This only calls summary tasks as Proc2 only seems interested in sub tasks.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    • Marked as answer by ATorng Wednesday, August 17, 2011 2:59 PM
    Wednesday, August 17, 2011 8:12 AM
    Moderator

All replies

  • Hello AndreT,

    What are you trying to do exactly?
    Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82
    Wednesday, August 17, 2011 7:27 AM
  • The ( ) around (vtask) is the problem. I would write the code as:

    Public Sub Proc1()
        Dim vTask As Task
        For Each vTask In ActiveSelection.Tasks
            If Not vTask Is Nothing Then
                Debug.Print vTask.ID; vTask.Name; vTask.Predecessors; vTask.Successors
                If vTask.Summary Then
                    Proc2 vTask
                End If
            End If
        Next vTask
    End Sub
    Public Sub Proc2(pTask As Task)
        Dim vTask As Task
        For Each vTask In pTask.OutlineChildren
            Debug.Print vTask.ID, vTask.Name, vTask.Predecessors, vTask.Successors
        Next vTask
    End Sub

    This only calls summary tasks as Proc2 only seems interested in sub tasks.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    • Marked as answer by ATorng Wednesday, August 17, 2011 2:59 PM
    Wednesday, August 17, 2011 8:12 AM
    Moderator
  • Rod -

    You da man!  No parenthesis?  I'd better remember that.

    Andre


    AndreT from MS Project Customization and Programming Forum
    Wednesday, August 17, 2011 2:59 PM