Priority

The Priority property returns a task or project priority.

Applies to

Project and Task objects

Data Type

Long

Access

Read/write

Remarks

The low eight bits of the Priority property’s value is a character.

The following sample code shows how the LConvertTo32bitPriority function converts the string parameter to a Long, which can be used as the priority in Automation (formerly OLE Automation):

‘ Valid formats for the string parameter are:
‘ "1"..."9"
‘ "A"..."Z"
‘ "A1"..."A9", "B1"..."B9", ... , "Z1"..."Z9"
‘ Anything else will return DefaultPriority as the priority,
‘ which is currently "3".

Function LConvertTo32bitPriority(ByVal PriorityText As String) As Long
Const DefaultPriority = &H2033  ' default priority = "3"
Dim PriorityNormal As String
Dim FirstChar As Integer
Dim LastChar As Integer

PriorityNormal = UCase(PriorityText)
    
Select Case Len(PriorityNormal)
Case 1
    If ((PriorityNormal >= "1") And (PriorityNormal <= "9")) Then
        LConvertTo32bitPriority = &H2000 + Asc(PriorityNormal)
    ElseIf ((PriorityNormal >= "A") And (PriorityNormal <= "Z")) Then
        LConvertTo32bitPriority = (Asc(PriorityNormal) * 256) + &H20
    Else
        LConvertTo32bitPriority = DefaultPriority
    End If

Case 2
    ‘ Verify that the first character is valid.
    FirstChar = Asc(PriorityNormal)
    If ((FirstChar < Asc("A")) Or (FirstChar > Asc("Z"))) Then
        LConvertTo32bitPriority = DefaultPriority
    Else
        ‘ Verify that the second character is valid.
        LastChar = Asc(Right(PriorityNormal, 1))

        If ((LastChar < Asc("1")) Or (LastChar > Asc("9"))) Then
            LConvertTo32bitPriority = DefaultPriority
        Else
            LConvertTo32bitPriority = (FirstChar * 256) + LastChar
        End If
    End If

Case Else
    ' If the string is too short or too long, return "3" as the priority
    ' should use schedule's default priority - left as exercise for the reader...
    LConvertTo32bitPriority = DefaultPriority
End Select

End Function
 

See Also

Project
Task