How do you pass multiple parameters to a Sub which has to be invoked?
Again, I've only been coding for about 3 days so please speak as if your trying to teach a child to tie his shoe.
Thanks :)
Printable View
How do you pass multiple parameters to a Sub which has to be invoked?
Again, I've only been coding for about 3 days so please speak as if your trying to teach a child to tie his shoe.
Thanks :)
The first argument to Invoke is the delegate and after that you just put all the arguments for the method being invoked, e.g. if you want to invoke this method:you would just do this:vb.net Code:
Private Sub DoSomething(ByVal arg1 As Object, ByVal arg2 As Object, ByVal arg3 As Object)When DoSomething is invoked, val1 will be passed to arg1, val2 to arg2 and val3 to arg3. You could also do it like this, and in fact had to before .NET 2.0:vb.net Code:
Me.Invoke(New DoSomethingDelegate(AddressOf DoSomething), val1, val2, val3)vb.net Code:
Me.Invoke(New DoSomethingDelegate(AddressOf DoSomething), New Object() {val1, val2, val3})
What if there are no parameters you need to pass?
Then don't pass any. Invoke takes one or more arguments. The first is required and is the delegate and the rest are optional and are the arguments for the method being invoked. If the method being invoked has 1000 arguments then you pass 1001 arguments to Invoke. If the method being invoked has no arguments then you pass 1 argument to invoke.