Hi Guys,
I’m new to UiPath.
Can you please help me convert this following code to usable code in Invoke Code activity where arrays and list will be dynamic and I will pass it as arguments.
This code is working in online compiler but pasting same in invoke code giving list of variaous errors
Thanks
Imports System
Imports System.Collections.Generic
Imports System.Linq
Public Class Program
Dim firstArray As String() = {"Durable Medical Equipment", "Durable Medical Supplies"}
Dim secondArray As String() = {"STANDARD SAVINGS", "Customer Non-Designated Providers"}
Dim thirdArray As String() = {"Office"}
Function ContainsAnyWord(str As String, words As String()) As String
For Each word In words
If str.Contains(word) Then
Return word
End If
Next
Return Nothing
End Function
Function FilterMyList(myList As List(Of String)) As Tuple(Of String, Boolean, String)
Dim matchedWords As New List(Of Tuple(Of String, String))()
Dim filteredList As List(Of String) = myList.Where(Function(item)
Dim match As String = ContainsAnyWord(item, firstArray)
If match IsNot Nothing Then
matchedWords.Add(Tuple.Create(item, match))
Return True
End If
Return False
End Function).ToList()
Dim multipleFirstArrayMatches As Boolean = filteredList.Count > 1
Dim matchedWord As String = If(matchedWords.Count > 0, matchedWords(0).Item2, Nothing)
If multipleFirstArrayMatches Then
filteredList = filteredList.Where(Function(item) ContainsAnyWord(item, secondArray) IsNot Nothing).ToList()
End If
filteredList = filteredList.Where(Function(item) ContainsAnyWord(item, thirdArray) Is Nothing).ToList()
Dim filteredString As String = If(filteredList.Count = 1, filteredList(0), Nothing)
multipleFirstArrayMatches = If(filteredString IsNot Nothing, False, multipleFirstArrayMatches)
Return Tuple.Create(filteredString, multipleFirstArrayMatches, matchedWord)
End Function
Public Shared Sub Main()
Dim program As New Program()
Dim myListType1 As New List(Of String) From {
"$150 Family STANDARD PLUS SAVINGS Customer Affiliated Providers Durable Medical Equipment,COPAY INCLUDED IN OOP",
"$30 Family MAXIMUM SAVINGS Customer Designated Providers Durable Medical Equipment,COPAY INCLUDED IN OOP",
"$0 Family STANDARD SAVINGS Customer Non-Designated Providers Durable Medical Supplies"
}
Dim myListType2 As New List(Of String) From {
"$0 Individual Home Durable Medical Equipment,Durable Medical Supplies,Copay Included In CATAS OOP",
"$0 Individual Office Continous Glucose Monitors,Continous Glucose Suppliers,Copay Included In CATAS OOP"
}
Dim myListType3 As New List(Of String) From {
"$0 Individual Home Durable Medical Equipment,Durable Medical Supplies,Copay Included In CATAS OOP",
"$0 Individual Office Durable Medical Equipment,Durable Medical Supplies,Copay Included In CATAS OOP"
}
Dim result1 = program.FilterMyList(myListType1)
Dim result2 = program.FilterMyList(myListType2)
Dim result3 = program.FilterMyList(myListType3)
Console.WriteLine(String.Format("Result 1: {0}, Multiple Matches: {1}, Matched Word: {2}", result1.Item1, result1.Item2, result1.Item3))
Console.WriteLine(String.Format("Result 2: {0}, Multiple Matches: {1}, Matched Word: {2}", result2.Item1, result2.Item2, result2.Item3))
Console.WriteLine(String.Format("Result 3: {0}, Multiple Matches: {1}, Matched Word: {2}", result3.Item1, result3.Item2, result3.Item3))
End Sub
End Class




