Passing values through delegates

I need help with the syntax for passing values through delegates.

I have a delegate:

Delegate Sub MethodCaller()

I have a method:

Sub AnotherMethod()
MsgBox(CurrentMethodName)
End Sub

I call it:

Dim callMethod As MethodCaller
callMethod = AddressOf AnotherMethod
callMethod.Invoke

All ok. Now I have a parameter I want to pass to the method

Delegate Sub MethodCaller(s As String)

Sub AnotherMethod(s As String)
MsgBox(s)
End Sub

Dim callMethod As MethodCaller
callMethod = AddressOf AnotherMethod “some string” <---------is this correct syntax?
callMethod.Invoke

I get an error.

Also can I have a delegate with different number of parameters like a method.

Delegate Sub MethodCaller()
Delegate Sub MethodCaller(s As String)
Delegate Sub MethodCaller(s As String, i As Integer)

Would appreciate some help.

That is the wrong syntax, you need:

callMethod.Invoke("some string")

You can not include arguments to a method via the AddressOf method. As for having methods overloaded, yes, I believe you can. Once you get the one working, it’ll be easy to test the other cases.

thanks. passing values work great. tried overloading and got “The name is already in use” error.

OK, I wasn’t sure, but I thought you could. Sorry about that.

no worries. i just with the documentation wasn’t so bad.

AddressOf doesn’t have a way to pick which one of the three variations you mean
Depending on what it is you need there may be other ways to do this