Jump to content

Passing an arbitrary number of parameters into a function?


Quinch
 Share

Recommended Posts

In my OutlookEX UDF I use the following approach:

You can pass up to 10 parameters to a function. If you need more you pack them into an array and pass the array as parameter one.

The code looks like:

; #FUNCTION# ====================================================================================================================
; Name ..........: _OL_DistListMemberAdd
; Description ...: Adds one or multiple members to a distribution list.
; Syntax.........: _OL_DistListMemberAdd($oOL, $vOL_Item, $sOL_StoreID, $vOL_P1 = ""[, $vOL_P2 = ""[, $vOL_P3 = ""[, $vOL_P4 = ""[, $vOL_P5 = ""[, $vOL_P6 = ""[, $vOL_P7 = ""[, $vOL_P8 = ""[, $vOL_P9 = ""[, $vOL_P10 = ""]]]]]]]]])
; Parameters ....: $oOL      - Outlook object returned by a preceding call to _OL_Open()
;                 $vOL_Item - EntryID or object of the distribution list item
;                 $sOL_StoreID - StoreID where the EntryID is stored. Use the keyword "Default" to use the users mailbox
;                 $vOL_P1     - Member to add to the distribution list. Either a recipient object or the recipients name to be resolved
;                 +           or a zero based one-dimensional array with unlimited number of members
;                 $vOL_P2     - Optional: member to add to the distribution list. Either a recipient object or the recipients name to be resolved
;                 $vOL_P3     - Optional: Same as $vOL_P2
;                 $vOL_P4     - Optional: Same as $vOL_P2
;                 $vOL_P5     - Optional: Same as $vOL_P2
;                 $vOL_P6     - Optional: Same as $vOL_P2
;                 $vOL_P7     - Optional: Same as $vOL_P2
;                 $vOL_P8     - Optional: Same as $vOL_P2
;                 $vOL_P9     - Optional: Same as $vOL_P2
;                 $vOL_P10   - Optional: Same as $vOL_P2
; Return values .: Success - Distribution list object
;                 Failure - Returns 0 and sets @error:
;                 |1 - No distribution list item specified
;                 |2 - Item could not be found. EntryID might be wrong
;                 |3 - Error adding member to the distribution list. @extended = number of the invalid member (zero based)
;                 |4 - Member name could not be resolved. @extended = number of the invalid member (zero based)
; Author ........: water
; Modified.......:
; Remarks .......: $vOL_P2 to $vOL_P10 will be ignored if $vOL_P1 is an array of members
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _OL_DistListMemberAdd($oOL, $vOL_Item, $sOL_StoreID, $vOL_P1, $vOL_P2 = "", $vOL_P3 = "", $vOL_P4 = "", $vOL_P5 = "", $vOL_P6 = "", $vOL_P7 = "", $vOL_P8 = "", $vOL_P9 = "", $vOL_P10 = "")

    Local $oOL_Recipient, $aOL_Recipients[10]
    If $vOL_Item = "" Then Return SetError(1, 0, 0)
    If Not IsObj($vOL_Item) Then $vOL_Item = $oOL.Session.GetItemFromID($vOL_Item, $sOL_StoreID)
    If @error <> 0 Then Return SetError(2, @error, 0)
    ; Move members into an array
    If Not IsArray($vOL_P1) Then
        $aOL_Recipients[0] = $vOL_P1
        $aOL_Recipients[1] = $vOL_P2
        $aOL_Recipients[2] = $vOL_P3
        $aOL_Recipients[3] = $vOL_P4
        $aOL_Recipients[4] = $vOL_P5
        $aOL_Recipients[5] = $vOL_P6
        $aOL_Recipients[6] = $vOL_P7
        $aOL_Recipients[7] = $vOL_P8
        $aOL_Recipients[8] = $vOL_P9
        $aOL_Recipients[9] = $vOL_P10
    Else
        $aOL_Recipients = $vOL_P1
    EndIf
    ; Rest of the function

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Why not use CMD parameters?

Note : only 63 parameters can be return by $CmdLine[...], but $CmdLineRaw will always returns the entire command line.

So if they are more then 63 - you can use $CmdLineRaw and split it manually

Link to comment
Share on other sites

Why not use CMD parameters?

Note : only 63 parameters can be return by $CmdLine[...], but $CmdLineRaw will always returns the entire command line.

So if they are more then 63 - you can use $CmdLineRaw and split it manually

He's been talking about internal functions, right?
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...