Help to to create the correct invoke code

Hi Guys i have a code below and i need your help to modify it so it will be suitable for UiPath invoce code activity

thank you

Function compare(name1 As String, name2 As String) As Long

    ' (1) Handle the YTD-Case:
    If Left(name1, 3) = "YTD" And Left(name2, 3) <> "YTD" Then
        compare = -1
    ElseIf Left(name1, 3) <> "YTD" And Left(name2, 3) = "YTD" Then
        compare = 1
    Else
        ' Compare the names without the leading number
        Dim pieces1() As String, pieces2() As String
        pieces1 = Split(name1, "_")
        pieces2 = Split(name2, "_")
    
        If UBound(pieces1) > 0 And UBound(pieces2) > 0 Then
            If pieces1(1) <> pieces2(1) Then
                ' different groups
                compare = IIf(pieces1(1) < pieces2(1), -1, 1)
            Else
                ' Same group, compare numbers
                If pieces1(0) = "0" Then
                    compare = 1
                    Exit Function
                ElseIf pieces2(0) = "0" Then
                    compare = -1
                    Exit Function
                Else
                    compare = Val(pieces1(0)) - Val(pieces2(0))
                End If
            End If
        Else
            ' Whatever that is: Compare names directly
            compare = IIf(name1 < name2, -1, 1)
        End If
    End If
End Function

Hi @StevenIsRobotOnline

Can I know what are you trying to do so that we can help you in modification.

Regards,

Hi
it is to rearrange excel sheet in alphabetical order based on sheetname, but i have one specific rule if sheet name contain “YTD” then its always 1st and if we have number 0 then it will always be at the end of its group

thank you

Input :

  • YTD-AA-
  • 1_AB
  • 3_AB
  • 2_AB
  • 0_AB
  • 2_NC
  • 0_NC
  • 1_NC

and i would like to arrange it like :

  • YTD-AA (excel sheet with “YTD” in the word will alwyas be the first )
  • 1_AB (follow up by the LEAST number and FIRST number found in order of A- Z)
  • 2_AB (follow up by the same group as the previous one (AB)
  • 3_AB
  • 0_AB (Ended in number ZERO ‘0’ on the same group (AB)
  • 1_NC (Continue on the next group after A - B - C etc. but always start again in the LEAST NUMBER MEANS IT CAN START FROM 2 IF 1 is not present )
  • 2_NC (follow up in the same group (NC) but now on next number after the previous
  • 0_NC (ended with number 0 )

1st off, invoke code does not support functions. So remove the Function and End Function statements. Remove the exit function statements nested in your if/else as well. Looking at the current code example and the way you nested all if/else blocks, this should have 0 impact on the logic.

Next, update your invoke activity by adding the 2 string variables and 1 long (=int64) variables in the arguments collection. Make sure that the directions (in / out) match your function.

i have limited knowledge in the programming, can you please share to me how to implement this dirently ?