Consulting

Results 1 to 4 of 4

Thread: How to determine #/type of function arguments via CODE

  1. #1
    VBAX Regular
    Joined
    Jun 2006
    Posts
    26
    Location

    How to determine #/type of function arguments via CODE

    I recently learned (via this site) how to list all of the functions/subs in a given module. Now I want to learn how determine the required number and type of arguments for these functions/subs. Any ideas out there?

    Thanks

  2. #2

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by nitt1995
    I recently learned (via this site) how to list all of the functions/subs in a given module. Now I want to learn how determine the required number and type of arguments for these functions/subs. Any ideas out there?

    Thanks
    I presume that the code you have parses the module text looking for Sub and Function to get the names. Just extend the parsing to look after the (. The Type will be after As (or variant if no As), before the next , or ).

  4. #4
    VBAX Regular
    Joined
    Jun 2006
    Posts
    26
    Location
    Quote Originally Posted by xld
    I presume that the code you have parses the module text looking for Sub and Function to get the names. Just extend the parsing to look after the (. The Type will be after As (or variant if no As), before the next , or ).
    I am actually collecting the functions using the .ProcOfLine method. From what I can figure out, this returns the procedure name at a given line without parsing the code.

    [vba]Function CollectProcedures(wb As Workbook, moduleName As String) As Collection
    Dim VBCodeMod As CodeModule
    Dim StartLine As Long
    Dim TempData() As Variant
    Dim ProcName As String

    Dim i As Integer
    Dim Count As Integer

    Dim procedures As New Collection
    Set VBCodeMod = wb.VBProject.VBComponents(moduleName).CodeModule
    With VBCodeMod
    'First Procedure is private, so don't include
    StartLine = .CountOfDeclarationLines + 1
    StartLine = StartLine _
    + .ProcCountLines(.ProcOfLine(StartLine, _
    vbext_pk_Proc), vbext_pk_Proc)
    Count = 0
    Do Until StartLine >= .CountOfLines
    Count = Count + 1
    procedures.Add .ProcOfLine(StartLine, vbext_pk_Proc)
    StartLine = StartLine + _
    .ProcCountLines(.ProcOfLine(StartLine, _
    vbext_pk_Proc), vbext_pk_Proc)
    Loop
    End With
    Set CollectProcedures = procedures
    End Function[/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •