vb.netms-project

MS Project. VB, Vb.NET. Application.CustomFieldValueListGetItem - How to get all Items?


How can i get all items in List?

Function "CustomFieldValueListGetItem" gets the elements only by index.

I don't know the last index. Can't find such property or function that returns it.

Is there any function like "GetAllItems as Array or Collection"? (MSDN didn't help)

So, to get that, i've wrote code, it works, but i don't like it.

 Dim MSPApp = oProjAct.Application
 Dim GetStr As String
 Dim CurrentArray(0)
 For y = 1 To 1500
   Try
     GetStr = MSPApp.CustomFieldValueListGetItem(PjCustomField.pjCustomTaskText2, PjValueListItem.pjValueListValue, y)
     ReDim Preserve CurrentArray(UBound(CurrentArray) + 1)
     CurrentArray(UBound(CurrentArray)) = GetStr
   Catch
       Exit For 'so if error - that's the last item.
   End Try
  Next


Solution

  • As previously pointed out, there is no Count method since there is no collection object exposed in the API. All the API offers is the CustomFieldValueListGetItem method to reach into that hidden collection object of custom field list values.

    Here is a variation of your code that, at least, reads a little better:

    Dim ListValues As New List(Of String)
    Try
        Dim idx As Int32 = 0
        Do While True AndAlso idx < 10000
            idx += 1
            ListValues.Add(ProjApp.CustomFieldValueListGetItem(PjCustomField.pjCustomTaskText2, PjValueListItem.pjValueListValue, idx))
        Loop
    Catch NoMoreItems As System.Exception
    End Try