How to use Message Box or MsgBox inside 'invoke code'? Getting error

Newbie here. I’m learning to use invoke code by following a tutorial. The very first simple code I wrote has errors already. I’m trying to simply show a message box with leap year. Here’s the code (in VB.net):

'FIND LEAP YEAR
Dim year As Integer
year = 2016
If year Mod 4 = 0 Then
	MsgBox("This is a leap year")
Else
	MsgBox("This is not a leap year")
End If

The error is:

Invoke Code: No compiled code to run
error BC30451: 'MsgBox' is not declared. It may be inaccessible due to its protection level. At line 15
error BC30451: 'MsgBox' is not declared. It may be inaccessible due to its protection level. At line 17

So, it seems it’s not recognizing MsgBox as a valid keyword. Is there another way? Is there an import I am missing? Is the keyword MsgBox not right? I’m learning so appreciate any explanation. The tutorial didn’t get this error so I’m confused. I seem to have the standard imports as listed here:

Hi @Terry_Marr ,

Check the properties of the invoke code activity, see if you have selected the language as Vb.net from the drop down.

If it is already set to the vb.net. Please share the code will check and provide a solution with you.

Thanks,
Gautham.

Hi @Terry_Marr

Try this code in Invoke Code:

'FIND LEAP YEAR
Dim year As Integer
year = 2016
If year Mod 4 = 0 Then
    message = "This is a leap year"
Else
    message = "This is not a leap year"
End If

Invoked Arguments:

Regards

Hi @Terry_Marr i have used same code you provided , for me its working . PFA

image

Hi Akhil–
I tried it again, and am getting the same error message. I must be not set up the same as you?

Yes it is Vbnet – here’s the code:

Dim year As Integer
year = 2016
If year Mod 4 = 0 Then
	MsgBox("This is a leap year")
Else
	MsgBox("This is not a leap year")
End If

same error:

`error BC30451: 'MsgBox' is not declared. It may be inaccessible due to its protection level. At line 6
`

I don’t understand why the tutorial guy had that code and no error, and also a respondent here tried my code and also had no error. Why am I having this error?

Hi @Terry_Marr

Probably Studio doesn’t support the message box inside the invoke code.

Try getting the string as output and pass that in a message box activity after the invoke code as @vrdabberu suggested.

@Akhil_Nukala , seems to be working for you if possible can you zip and share the entire folder.?

Thanks,
Gautham.

I stripped the code to barebones for testing and tried many variations. Finally, this works:

System.Windows.MessageBox.Show("hello")

I couldn’t get MsgBox to work on its own. I imported system.windows.forms and that didn’t work. MessageBox is “ambiguous” in a couple of imports, so the full namespace as in code above seems to be needed. This is my first foray into UiPath invoke code. I hope it’s not always this hard to get something so simple to work.

2 Likes

Hi @Gautham_Pattabiraman here i am attaching
MsgBox_Invokecode.zip (2.5 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.