Invoke Code syntax error

Hi there,

I’m trying create a piece of code to do some string find/replace using InvokeCode but I’m running into a syntax error that I can’t figure out.

Dim test01 As String = “#first string# here is some text #second string# and more text”
Dim test02 As String = “#first string# here is some more text I don’t care about”
Dim items As New System.Collections.Generic.List(Of Integer)
items = test01.Select(Function(c, i) New With {.Character = c, .Index = i}) _
.Where(Function(item) item.Character = “#”) _
.ToList
Dim count As Integer = items.Count

This works in Visual Studio but I’m getting an error message that on the “items =” line: the List(Of anonymous type) can’t be converted to List(Of Integer)

Any ideas?

Thanks,

Carlo.

Can you let me know what is the project type you have selected for writing the above code? @carlor

You need to use VB → Windows Form Application project

so that everything will work fine in UiPath as well. (except the message box and few things)

Message box in Uipath will be : System.Windows.MessageBox.Show

and in visual studio, it will be : MessageBox.Show

Sorry, but I’m not sure what you mean. This is in a UIPath project and it is in an Invoke Code block (UIPath.Core.Activities.InvokeCode)

Thanks,

Carlo.

I mean, what is the project type you selected for writing the above code in Visual studio?

@carlor
It seems to me that the part … new With creating an anonymus Object is forwarded as type to the toList() statement. Does mean. Statement is returning a list of anonymous object and not a list of Int

Give a try on test01.Select(Function(c, i) New With {.Character = c, .Index = i}) _
.Where(Function(item) item.Character = “#”) _
.ToList.Count() (As you are finally interested on the count, right?)

or use a Select before toList for projecting a dedicated part of the anononymous object

Ah. It’s a console application in VS. The code compiles in VS and runs fine. The problem is that the same code, in the UIPath “InvokeCode” has an error.

Thanks,

Carlo.

Thanks, but I’m not interested in the count. I’m only using that as a test to see if this works. What I want to do is the string manipulation I mentioned above.

Carlo.

Ok fine, so lets focus on this