tags:

views:

79

answers:

4

Is it possible to get the arguments from a sub or function in vb2005 as an array?

A: 

You can do it in VS 2010, but not 2005. This is a feature being added via the DLR or Dynamic Language Runtime.

Jonathan Allen
A: 

Using reflection:

Dim params() As System.Reflection.ParameterInfo = myObject.GetType().GetMethod("myObjectMethodName").GetParameters()
ozczecho
appears to be half right, in my sub it shows up defined as "nothing",let me rephrase, how do i get the values of my arguments as an array from within the sub or function
Jim
A: 

If you have control over the member signature, then you could encapsulate all of the parameters into a single class, much like how an EventArgs object (or subclass thereof) is passed between event handlers in the conventional .NET manner.

Then just pass all the values by passing a reference to the encapsulating class itself.

Rabid
+1  A: 

Hi Jim, did you solve this? I'm not too sure about what you mean, but from your comment on your OP, are you looking to synchronize threads to make calls thread-safe?

Private WithEvents theThread As New threadedClass
Private Delegate Sub threaded_method_delegate(ByVal sender As Object, ByVal var1 As Integer, ByVal var2 As String)

Sub threaded_method(ByVal sender As Object, ByVal var1 As Integer, ByVal var2 As String) Handles theThread.threaded_method
 If Me.InvokeRequired Then
  ' invoke this method on the same thread as 'Me'
  Dim d As New threaded_method_delegate(AddressOf threaded_method)
  d.Invoke(sender, var1, var2)
 Else
  ' this method is now running on the same thread
  ' do stuff here
 End If
End Sub
Wez