Iterate through parameters in a function?

Last post 05-10-2005 9:48 AM by DarrellNorton. 1 replies.

Sort Posts:

  • Iterate through parameters in a function?

    05-09-2005, 4:45 PM
    • Participant
      1,130 point Participant
    • Philotech
    • Member since 03-17-2003, 3:30 PM
    • Posts 227

    Is there a way I can iterate through the parameter that are sent to a function?

    i.e.
    private function somthing(ByVal This As String, ByVal That As String, ByVal Something As String)

    End Function

    Is there a way to access the values in This, That, and Something without using their name? say in a for loop?

    Also, How do you do optional paramers in Visual Basic.Net

  • Re: Iterate through parameters in a function?

    05-10-2005, 9:48 AM
    • All-Star
      54,821 point All-Star
    • DarrellNorton
    • Member since 04-04-2003, 3:49 PM
    • VA, USA
    • Posts 6,600
    • Moderator
      TrustedFriends-MVPs
    You can use reflection.  Here's a sample:

    [Visual Basic] 
    ' The following example uses instances of classes in
    ' the System.Reflection namespace to discover an event argument type.
    Imports System
    Imports System.Reflection
    Imports Microsoft.VisualBasic

    Public Class MainClass
    Delegate Sub MyDelegate(ByVal i As Integer)
    Public Event ev As MyDelegate
    Public Sub Fire(ByVal i As Integer)
    AddHandler ev, AddressOf Me.Fire
    End Sub 'Fire

    Public Shared Sub Main()
    Dim deleg As Type = GetType(MainClass).GetEvent("ev").EventHandlerType
    Dim invoke As MethodInfo = deleg.GetMethod("Invoke")
    Dim pars As ParameterInfo() = invoke.GetParameters()
    Dim p As ParameterInfo
    For Each p In pars
    ' YOUR CODE HERE
    Next p
    End Sub 'Main
    End Class 'MainClass


    Darrell Norton, MVP
    Darrell Norton's Blog


    Please mark this post as answered if it helped you!
Page 1 of 1 (2 items)