Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    I am looking for a general snippet that can be used to capture in an array, the arguments which were passed to the current procedure or function. I visualize something akin to the following, but do not know of any way to determine properties of a procedure such as which arguments were passed to it.
    Any insight will be greatly appreciated.
    [codebox] For ctr = 1 To PassedArguments.Count
    myArray(ctr) = PassedArguments(ctr)
    Next
    [/codebox]
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    [quote name='wdwells' post='762605' date='01-Mar-2009 15:18'][/quote]
    I don't think you can do that unless you use ParamArray in the declaration of the procedure or function.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thank you Hans
    I have come to the same conclusion. Passing the array as an argument achieves the desired results with no added agony.
    Regards
    Don

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    [quote name='wdwells' post='762703' date='02-Mar-2009 01:18']Thank you Hans
    I have come to the same conclusion. Passing the array as an argument achieves the desired results with no added agony.[/quote]

    If you were not using ParamArray, then you could simply declare the array and populate it as required given that you know at design time what the inputs are. I'm not really sure what purpose it would serve though?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I sometimes do is use a custom type. This makes adding an argument simple:

    [codebox]Option Explicit

    Public Type People
    FirstName As String
    LastName As String
    Street As String
    End Type

    Sub Example()
    Dim tPerson As People
    With tPerson
    .FirstName = "Jan"
    .LastName = "Pieterse"
    .Street = "Churchlane"
    End With
    ShowPerson tPerson
    End Sub

    Sub ShowPerson(tPerson As People)
    With tPerson
    MsgBox .FirstName & " " & .LastName & vbNewLine & .Street
    End With
    End Sub
    [/codebox]
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='pieterse' post='763058' date='03-Mar-2009 11:31']What I sometimes do is use a custom type.[/quote]
    Me too.
    In particular, within a VBA project, or better yet, within a client's project (which may consist of several VBA Application projects), if I can create a self-descriptive TYPE, I can do all sorts of useful debugging things.
    A self-descriptive TYPE being one where the first item is, say, a LONG that describes the number of dimensions of a parameter array, the next Val(lng) items are the size of each dimension, and then next item is the array.
    Or sometimes, paired items that tell me the type as well as the dimension.
    And so on.

    MARC library records were a popular example of this technique years ago.

    I wish that VBA made available to us poor mortals the descriptors of data, so we could interrogate them instead of relying on trial and On Error.

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='wdwells' post='762605' date='02-Mar-2009 01:18'] I am looking for a general snippet that can be used to capture in an array, the arguments which were passed to the current procedure or function. [/quote]

    I'm not sure what you're wanting to do here, but I've often used the Join and Split functions to "carry" multiple values in a single (global?) variable, which can be easily transformed to an array. See VB String Array Functions - Split, Join, Filter (VB6) for example.

    Alan

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='AlanMiller' post='763313' date='04-Mar-2009 07:28']I'm not sure what you're wanting to do here, but I've often used the Join and Split functions to "carry" multiple values in a single (global?) variable, which can be easily transformed to an array. See VB String Array Functions - Split, Join, Filter (VB6) for example.

    Alan[/quote]
    Thanks for the input Alan
    As soon as I hit the send button on my original post I realized that if I wanted to create an array of arguments in the called procedure, the simplest way would be to create the array in the calling procedure and pass the array.
    Regards
    Don

Posting Permissions

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