none
VBA to Analyze Predecessor for instances of FF RRS feed

  • Question

  • I'm trying to identify "dangling ends" in predecessor and successor fields. In the predecessor field, I'm looking for instances where only "FF" predecessor(s). Similarly I'm wanting to do the same thing in the successor field but looking for instances where only SS successors exist. I've got code that uses the TaskDependencies object, and I can spin thru it's contents and successfully identify the dependency types (FF, SS, FS, SF) but I'm unable to differentiate whether the dependency is in the predecessor field or the successor field.

    Any suggestions would be appreciated.

    Thanks in advance,

    Dan

     
    Friday, August 28, 2020 2:18 PM

Answers

  • Dan,

    The TaskDependencies Property has subproperties of "from" and "to". The "from" property is the predecessor part and the "to" property is the successor part.

    Suggestion. You might find it easier to first have your code create and apply custom filters that select out "FF" in the Predecessor and Successor fields and then operate on those selected sets.

    Hope this helps.

    John

    • Marked as answer by dfeigen115 Friday, August 28, 2020 5:21 PM
    Friday, August 28, 2020 4:49 PM
  • Dan,

    This is a bit crude, but it does most of what you want. I didn't expand it to weed out 1FF versus 1FF,2FF (both bad, I think), but I'll leave that as an exercise for the student.

    John

    • Marked as answer by dfeigen115 Tuesday, September 1, 2020 4:22 PM
    Monday, August 31, 2020 8:21 PM
  • Dan,

    This is one of those cases where you test for proof of a negative.  I.e.  assume that the task has a dangling start/finish, then search for a relationship that disproves the assumption.  The code block below will identify all open starts as dangling starts and all open finishes as dangling finishes.  (It doesn't make the customary distinction between a task with dangling start and one with no predecessors at all.  The latter is a simple check.)  I've used the Select Case method here to match your description, though I don't think it's very efficient.  My add-in is a bit more streamlined.  Obviously, I've left the task looping out, also.  Good luck, tom

    Sub SimpleCheckDanglers()
        Dim t As Task
        Dim d As TaskDependency
        Dim tDS As Boolean
        Dim tDF As Boolean
       
        Set t = ActiveCell.Task
           'Assume dangling start/finish then prove otherwise
            tDS = True
            tDF = True
            For Each d In t.TaskDependencies
                Select Case d.Type
                    Case pjFinishToStart
                        If d.To.Guid = t.Guid Then tDS = False
                            'This is a predecessor dependency on start
                        If d.From.Guid = t.Guid Then tDF = False
                            'This is a successor dependency on finish
                    Case pjStartToStart
                        If d.To.Guid = t.Guid Then tDS = False
                            'This is a predecessor dependency on start
                    Case pjFinishToFinish
                        If d.From.Guid = t.Guid Then tDF = False
                            'This is a successor dependency on finish
                    Case pjStartToFinish
                        'No impact for this dependency type
                End Select
            Next d
        Debug.Print "Task ID: " & t.ID _
        & vbTab & "  Dangling Start: " & tDS _
        & vbTab & "  Dangling Finish: " & tDF
    End Sub

     
    • Edited by Tom BoyleBPC Monday, August 31, 2020 10:27 PM
    • Marked as answer by dfeigen115 Tuesday, September 1, 2020 4:22 PM
    Monday, August 31, 2020 10:24 PM

All replies

  • Dan,

    The TaskDependencies Property has subproperties of "from" and "to". The "from" property is the predecessor part and the "to" property is the successor part.

    Suggestion. You might find it easier to first have your code create and apply custom filters that select out "FF" in the Predecessor and Successor fields and then operate on those selected sets.

    Hope this helps.

    John

    • Marked as answer by dfeigen115 Friday, August 28, 2020 5:21 PM
    Friday, August 28, 2020 4:49 PM
  • thanks John - that gives me what I need.
    Friday, August 28, 2020 5:21 PM
  • Dan,

    You're welcome and thanks for the feedback.

    John

    Friday, August 28, 2020 5:48 PM
  • John,could you provide a quick example of the format to reference the from & to objects. 

    Friday, August 28, 2020 6:47 PM
  • Pending John's return, this should get you going....  Checking whether two objects are the same is not always easy - I find using guid is pretty foolproof in most environments.

    Sub CheckPreds()
        Dim t As Task
        Dim d As TaskDependency
        
        Set t = ActiveCell.Task
        For Each d In t.TaskDependencies
            If d.To.Guid = t.Guid Then
                'This is a predecessor dependency
                'Print the name of the predecessor task
                Debug.Print d.From.Name
            End If
        Next d
    End Sub


    • Edited by Tom BoyleBPC Friday, August 28, 2020 8:43 PM explained guid
    Friday, August 28, 2020 8:40 PM
  • Thanks Tom
    Friday, August 28, 2020 9:16 PM
  • Dan,

    Sorry for the delay, perhaps Tom's approach gave some insight. Nonetheless, here is a simple plan with a few linked tasks. The code lists all predecessors and successors for each task. Note, and I never quite understood why, each task lists itself as one of the dependencies. Maybe that speaks to "self reliance", I don't know.

    Again, if I were searching for specific link types, I'd use the filter approach. Just remember that a filter might yield no tasks so the code must be able to work around that.

    John

    Saturday, August 29, 2020 5:15 PM
  • John, Tom,

    thanks for bearing with me on this. a little more background and detail. I've got a rather robust VBA module that performs about 100 or so checks for compliance (corporate, DCMA, general best practices).  It spins thru each task performing a wide range of evaluations.  

    I can evaluate the TaskDependencies Type to id the type of dependency SS, FF, FS, or SF." <o:p></o:p>

    I'm using a "For Each tdep In tsk.TaskDependencies" loop in which it does a "Select Case on tdep.type". This portion works as noted above<o:p></o:p>

    The key check I'm having issues with is finding instances where there is an FF predecessor without a non-FF predecessor or if there is an SS successor without a non-SS successor. E.g. pred=1FF is bad, pred=1FF,2 is good.

    <o:p style="">So while I can identify the dependency type, I'm unable to identify if it is in the predecessor or successor field. I've tried variations of the info both of you have provided to no avail.</o:p>

    Dan

    Monday, August 31, 2020 6:13 PM
  • Dan,

    This is a bit crude, but it does most of what you want. I didn't expand it to weed out 1FF versus 1FF,2FF (both bad, I think), but I'll leave that as an exercise for the student.

    John

    • Marked as answer by dfeigen115 Tuesday, September 1, 2020 4:22 PM
    Monday, August 31, 2020 8:21 PM
  • Dan,

    This is one of those cases where you test for proof of a negative.  I.e.  assume that the task has a dangling start/finish, then search for a relationship that disproves the assumption.  The code block below will identify all open starts as dangling starts and all open finishes as dangling finishes.  (It doesn't make the customary distinction between a task with dangling start and one with no predecessors at all.  The latter is a simple check.)  I've used the Select Case method here to match your description, though I don't think it's very efficient.  My add-in is a bit more streamlined.  Obviously, I've left the task looping out, also.  Good luck, tom

    Sub SimpleCheckDanglers()
        Dim t As Task
        Dim d As TaskDependency
        Dim tDS As Boolean
        Dim tDF As Boolean
       
        Set t = ActiveCell.Task
           'Assume dangling start/finish then prove otherwise
            tDS = True
            tDF = True
            For Each d In t.TaskDependencies
                Select Case d.Type
                    Case pjFinishToStart
                        If d.To.Guid = t.Guid Then tDS = False
                            'This is a predecessor dependency on start
                        If d.From.Guid = t.Guid Then tDF = False
                            'This is a successor dependency on finish
                    Case pjStartToStart
                        If d.To.Guid = t.Guid Then tDS = False
                            'This is a predecessor dependency on start
                    Case pjFinishToFinish
                        If d.From.Guid = t.Guid Then tDF = False
                            'This is a successor dependency on finish
                    Case pjStartToFinish
                        'No impact for this dependency type
                End Select
            Next d
        Debug.Print "Task ID: " & t.ID _
        & vbTab & "  Dangling Start: " & tDS _
        & vbTab & "  Dangling Finish: " & tDF
    End Sub

     
    • Edited by Tom BoyleBPC Monday, August 31, 2020 10:27 PM
    • Marked as answer by dfeigen115 Tuesday, September 1, 2020 4:22 PM
    Monday, August 31, 2020 10:24 PM
  • John, Tom, 

    Thanks for your assistance. I actually used portions of both methods and it works perfectly, it successfully  differentiates between dangling & non-dangling FF & SS dependencies regardless of the combinations of dependency types that may be present.

    Dan 

    Tuesday, September 1, 2020 4:30 PM
  • Dan,

    You're welcome and thanks for the feedback.

    Wow, ain't the power of group think just the cat's meow?

    John

    Tuesday, September 1, 2020 5:22 PM
  • Glad you got it sorted.
    Tuesday, September 1, 2020 6:54 PM