Field value discrepancy RRS feed

  • 問題

  • This is part of a much larger add-on, but essentially I'm seeing a different field value depending on how I access the data. See the following example:


    Sub test()

        Dim test As Date
        test = ActiveProject.Tasks(4).Start
        Dim test2 As Date
        test2 = ActiveProject.Tasks(4).GetField(PjField.pjTaskStart)
    End Sub

    test & test2 are getting different dates. I would've guessed that those statements should yield identical values. I'm not sure all of what's required to reproduce the issue, but essentially let's say I have Task 1 & Task 2 and Task 1 is a predecessor of Task 2. The date that I'm getting with GetField on Task 2 seems to earlier than it should be when I adjust the start time of Task 2 to be a few days out. 

    • 已編輯 David Cor 2019年10月17日 下午 09:05
    2019年10月17日 下午 08:56


  • So using GetField(PjField.pjTaskStartText) returns the correct text, not a clue why though so I'm not sure it's really the correct solution in my case.
    2019年10月17日 下午 09:09
  • David Cor,

    Okay, something doesn't quite make sense. You say Task 1 is the predecessor of Task 2. Then you say you "adjust" the start time of Task 2 to be a few days out. What does that mean?

    And what do you mean by, "Task 2 seems to be earlier than it should be"?

    I don't see anything wrong with your simple code example but before we can be of much help we need to better understand your scenario. A more detailed explanation or a screen shot, if possible, would help. Also, how exactly are you "reading" the values of test and test2?


    • 已編輯 John - Project 2019年10月17日 下午 10:11 one more thing
    2019年10月17日 下午 10:08
  • Since Project created manual tasks, Start can hold text data. So if you want a valid date, try using .ScheduledStart

    Rod Gill
    Author of the one and only Project VBA Book and VBA developer.

    2019年10月19日 上午 04:03
  • Hi David, 

    I was able to reproduce your issue with manually scheduled tasks in the following test project:

    Task Name  Duration  Start Date                Finish Date              Predecessor  Scheduled Start

    Task 1 1 dy? Mon 21.10.19 08:00 Mon 21.10.19 17:00 Mon 21.10.19 08:00
    Task 2 1 dy         Thu 24.10.19 08:00 Thu 24.10.19 17:00 1 Tue 22.10.19 08:00


    The code I used is nearly the same as you used:

    Sub test()
        Dim test As Date
        test = ActiveProject.Tasks(2).Start
        MsgBox test
        Dim test2 As String
        test2 = ActiveProject.Tasks(2).GetField(PjField.pjTaskStart)
        MsgBox test2
    End Sub

    So GetField(PjField.pjTaskStart) always seems to return the value in the field Scheduled Start, in this case 21st October 2019, because Task 1 is the predecessor of Task 2. Rod Gil already wrote, you could use the field Scheduled Start to get the same Date in both of the statements.

    If you want to get the text value in the Start Date field of the manually scheduled task you could use "PjField.pjTaskStartText". This will return exactly the string in the Task Start field.

    2019年10月19日 下午 09:45