How to call a function in invokecode?

Good day!
Faced a problem, wrote a method, but how now to call it?
Let me explain there is a method, it performs for example the following code:

Sub start()
MsgBox("123")
End Sub

It seems to me somehow it is necessary to call this method, but how? please tell me ))

if you run it like this, it gives an error:

Invoke code : Error compiling code
error BC30289: Statement cannot appear within a method body. End of method assumed. At line 3
error BC30429: 'End Sub' must be preceded by a matching 'Sub'. At line 9
1 Like

Hi,

you can remove the sub and end sub.
Then use the code inside the function with proper parameters, it will work then.

1 Like

Error ID BC30289 - Statement cannot appear within a method body

https://docs.microsoft.com/en-us/dotnet/visual-basic/misc/bc30289

A procedure contains an invalid statement such as another procedure declaration. Procedure declarations cannot be nested.

@sarathi125 suggestion is right, remove the subroutine.

If you did want to work with functions, take a look at the following reference to using a Lambda

2 Likes

Thank you, with this I understood everything, functions, methods are declared through lambda expressions, but the question arises next, how to declare a class?
I need this code to work:

Dim people As New List(Of Person)(3)
        people.Add(New Person() With {.Name = "Tom"})
        people.Add(New Person() With {.Name = "Bill"})
        For Each p As Person In people
            MsgBox(p.Name)
        Next
       Console.ReadLine()
    End Sub
 
    Class Person
        Public Property Name() As String
    End Class
        Public Property Name () As A String
    End Class