InvokeCode Example

Main has thrown an exception

Source: Invoke code

Message: Error compiling code
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 1
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 1
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 2

Exception Type: ArgumentException

System.ArgumentException: Error compiling code
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 1
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 1
error BC30451: ‘Cursor’ is not declared. It may be inaccessible due to its protection level. At line 2

at UiPath.Core.Activities.Workflow.CompilerRunner.Compile(String code, Int32 errLineOffset)
at UiPath.Core.Activities.InvokeCode.GetCompilerRunner(String userCode, List`1 args, String imps)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

2 Likes

Create Cursor argument of Type System.Windows.Forms.Cursor

3 Likes

It’s working thanks a lot

2 Likes

Hi I need to Execute following Code, Please guide me

Dim oWB As Excel.Workbook
        Dim oSheet As Excel.Worksheet
        Dim oRng As Excel.Range

        ' Start Excel and get Application object.
        oXL = CreateObject("Excel.Application")
        oXL.Visible = True

        Sheets(Sheets.Count).Activate

I need to select last sheet of the excel workbook

1 Like

Hi,

I tried this but am unable to get it to work. The error I get are the same as this:

Please try this

1 Like

Hi why am i getting module member declaration expected?

image

1 Like

Hi ,
I have written this code how can i make it work using invoke code activity please help

Imports System.IO

Module Module1

Private index1 As Integer = New StringHelper().GetIndexofSearchText("C:\Users\vivekver\Documents\UiPath\Nokia Automation\Configuration Manager Nokia 2nd\TEST.txt", "MRBTS-486203")
Private index2 As Integer = New StringHelper().GetIndexofSearchText("C:\Users\vivekver\Documents\UiPath\Nokia Automation\Configuration Manager Nokia 2nd\TEST.txt", "[TopologyNode: PLMN-PLMN/MRBTS-486215]")
Public index_Hotkey As Integer = New NoOfHotkeys().GetHotkey(index1, index2)

Public Class NoOfHotkeys
    Public Function GetHotkey(ByVal index1 As Int32, ByVal index2 As Int32)
        Dim index_Hotkey As Integer = index2 - index1
        Return index_Hotkey

    End Function

End Class
Public Class StringHelper

    Public Function GetIndexofSearchText(ByVal Filename As String, ByVal SearchText As String) As Integer
        Dim index As Integer = 0
        Dim lines As List(Of String) = File.ReadLines(Filename).ToList()
        For Each line In lines
            If line.Contains(SearchText) Then
                Return index
            End If

            index += 1
        Next

        Return index


    End Function
End Class

Sub Main()


End Sub

End Module

i want index_Hotkey as output to my uipath workflow.Please help

Hi the activity is to read text file line by line until it finds a string and simuntaneously increment a index to know row index of line till it finds the string.Please help

Hi,

i am new to uipath and i am trying to use the invoke code activity to work on excel for that i have imported Microsoft.office.interop.excell through import tab in uipath studio but still gettting error for Excel.

could you pleae guide me how to use the external dll in invoke code.

1 Like

Hi,

Please refer the below tutorial.

Thanks,
Karthik.

3 Likes

Does Invoke code reduces the performance of the Robot process compared to Activities ??

I need with a justifying answer. kindly help me out.

Hi @blaze.1411,

May be. Because we have to see how we are writing the code. And it accepts VB.Net.
The activities has been handled object well. I am not sure that we can able to do all the things in the Invoke code.
I read the invoke code will get slow . I have seen a post the below.

Note :slight_smile:
Some situation we can not avoid the Invoke code activity …

Regards
Balamurugan.S

Take a look at this, i found it takes same time to process. I am unable to figure out it clearly in the view of memory consumption.

1 Like

Hi @blaze.1411,

Thats y I said may be. Depends upon the situation. But the time study is good one when we go with the performance. And if you have an activity for example to Open browser. you can use it. Unnecessarily why you are using invoke code. It takes your time also, But really I like these conversation in the form.

Regards
Balamurugan.

1 Like

Ok ! Thank You ! @balupad14 !!

Welcome @blaze.1411

Dear all, I would like to enter a VB.Net code to change my windows password. Any experiences for doing so? I have tried:

Dim res As NET_API_STATUS = NetUserChangePassword(Environment.UserDomainName, Environment.UserName, oldPass, newPass)
If res <> NET_API_STATUS.NERR_Success Then
Throw New ApplicationException(“Error setting password - Error code:” &res.ToString())
End If

However, I am getting the following error:
Error compeling code:
Error BC30002 Type: NET_API_STATUS is not defined. At line 1 Error BC30451: NET_API_STATUS is not declared. It might be due to its protection level at line 2.

Thanks!

I need to invoke below code in uipath, can anyone help me.

Using System;
Using System.Globalization;

Public Class Program
{
Public Static void Main()
{
DateTime time = New DateTime(2020, 4, 2);
Console.WriteLine(time.GetWeekOfMonth());
}
}

Static Class DateTimeExtensions {
Static GregorianCalendar _gc = New GregorianCalendar();
Public Static int GetWeekOfMonth(this DateTime time) {
DateTime first = New DateTime(time.Year, time.Month, 1);
Return time.GetWeekOfYear() - first.GetWeekOfYear() + 1;
}

Static int GetWeekOfYear(this DateTime time) {
    Return _gc.GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
}

}

Regards,
Dilini

1 Like

What issue are you running into when you try to just copy + paste into an invoke code activity?

Also, why are you using invoke code for this? This is a relatively simple piece of code and I dont think I understand what the advantage would be for using invoke code? It could be done using a few assign activities instead which would be quicker and easier for others to understand.