Jump to content

[Closed] Can a Function in AutoIt be Defined with a ParametersArray?


Zohar
 Share

Recommended Posts

Hi

 

Is there a way to define a Function in AutoIt, something like this:

Func SomeFunction($ParamsArray)
     ;code
EndFunc

Where the developer that uses this function, can then call it with any number of parameters, seperated by a ',' like this:

SomeFunction("hello","hi","test","etc")

and then inside the function, the function will receive a $ParamsArray which it can work on?

 

Thank you

Zohar

Edited by Zohar
Link to comment
Share on other sites

  • Moderators

Zohar,

No, you need to put those parameters into an array before you pass it to the function. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

H Melba

That's what I do now..

But I ask about it because I saw the Call() function in AutoIt, which can get any number of parameters..

See its definition:

Call ( "function" [, param1 [, param2 [, paramN ]]] )

You see it can get param1..paramN

So maybe this is accessible to us too?

So we can define a function like this?

Link to comment
Share on other sites

A function can have up to 30 parameters.

@NumParams is set to the number of passed parameters.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

You could write one function that takes a variable amount of parameters, use @NumParams to dynamically create an array, and then call the "real" function with that.
I guess it would be kinda like CallArgArray but opposite.

But I feel like it would be easier to just use the variables directly instead of messing around with Eval() (or however you would do the above).

Link to comment
Share on other sites

Yes only work arounds.

If you want to suggest to the devs to implement a feature like this, follow the BugTracker link at the top of the page and create a feature request.

Link to comment
Share on other sites

  • Moderators

Zohar,

Already a feature request: #2278. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

That params in C# is pretty powerful.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@water

 

A function can have up to 30 parameters.

 

If you don't mind me asking, were does it say that a function can have only 30 parameters?  

Here is a test function with 100 parameters.

Global $iReturn = _Test(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
                        1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
ConsoleWrite($iReturn & @LF)

Func _Test($param1, $param2, $param3, $param4, $param5, $param6, $param7, $param8, $param9, $param10, _
            $param11, $param12, $param13, $param14, $param15, $param16, $param17, $param18, $param19, $param20, _
            $param21, $param22, $param23, $param24, $param25, $param26, $param27, $param28, $param29, $param30, _
            $param31, $param32, $param33, $param34, $param35, $param36, $param37, $param38, $param39, $param40, _
            $param41, $param42, $param43, $param44, $param45, $param46, $param47, $param48, $param49, $param50, _
            $param51, $param52, $param53, $param54, $param55, $param56, $param57, $param58, $param59, $param60, _
            $param61, $param62, $param63, $param64, $param65, $param66, $param67, $param68, $param69, $param70, _
            $param71, $param72, $param73, $param74, $param75, $param76, $param77, $param78, $param79, $param80, _
            $param81, $param82, $param83, $param84, $param85, $param86, $param87, $param88, $param89, $param90, _
            $param91, $param92, $param93, $param94, $param95, $param96, $param97, $param98, $param99, $param100)

    ConsoleWrite("@NumParams: " & @NumParams & @LF)

    Return $param1 + $param2 + $param3 + $param4 + $param5 + $param6 + $param7 + $param8 + $param9 + $param10 + _
    $param11 + $param12 + $param13 + $param14 + $param15 + $param16 + $param17 + $param18 + $param19 + $param20 + _
    $param21 + $param22 + $param23 + $param24 + $param25 + $param26 + $param27 + $param28 + $param29 + $param30 + _
    $param31 + $param32 + $param33 + $param34 + $param35 + $param36 + $param37 + $param38 + $param39 + $param40 + _
    $param41 + $param42 + $param43 + $param44 + $param45 + $param46 + $param47 + $param48 + $param49 + $param50 + _
    $param51 + $param52 + $param53 + $param54 + $param55 + $param56 + $param57 + $param58 + $param59 + $param60 + _
    $param61 + $param62 + $param63 + $param64 + $param65 + $param66 + $param67 + $param68 + $param69 + $param70 + _
    $param71 + $param72 + $param73 + $param74 + $param75 + $param76 + $param77 + $param78 + $param79 + $param80 + _
    $param81 + $param82 + $param83 + $param84 + $param85 + $param86 + $param87 + $param88 + $param89 + $param90 + _
    $param91 + $param92 + $param93 + $param94 + $param95 + $param96 + $param97 + $param98 + $param99 + $param100
EndFunc

Adam

Link to comment
Share on other sites

Good question. It came off the top of my head. Unfortunately I can't find any evidence in the help file.

Maybe a limitation that was lifted some time ago?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Not sure of the appeal...something like this?

;~ ;~Create the params for a function
;~ ConsoleWrite("$" & $i)
;~ For $i = 2 To 200
;~  ConsoleWrite(",$" & $i & "=Default")
;~ Next
;~ ConsoleWrite(@CRLF)
#include <Array.au3>
Lazy_SomeFunction("some","string","here","as","you","see","fit")

Func Lazy_SomeFunction($1,$2=Default,$3=Default,$4=Default,$5=Default,$6=Default,$7=Default,$8=Default,$9=Default,$10=Default,$11=Default,$12=Default,$13=Default,$14=Default,$15=Default,$16=Default,$17=Default,$18=Default,$19=Default,$20=Default,$21=Default,$22=Default,$23=Default,$24=Default,$25=Default,$26=Default,$27=Default,$28=Default,$29=Default,$30=Default,$31=Default,$32=Default,$33=Default,$34=Default,$35=Default,$36=Default,$37=Default,$38=Default,$39=Default,$40=Default,$41=Default,$42=Default,$43=Default,$44=Default,$45=Default,$46=Default,$47=Default,$48=Default,$49=Default,$50=Default,$51=Default,$52=Default,$53=Default,$54=Default,$55=Default,$56=Default,$57=Default,$58=Default,$59=Default,$60=Default,$61=Default,$62=Default,$63=Default,$64=Default,$65=Default,$66=Default,$67=Default,$68=Default,$69=Default,$70=Default,$71=Default,$72=Default,$73=Default,$74=Default,$75=Default,$76=Default,$77=Default,$78=Default,$79=Default,$80=Default,$81=Default,$82=Default,$83=Default,$84=Default,$85=Default,$86=Default,$87=Default,$88=Default,$89=Default,$90=Default,$91=Default,$92=Default,$93=Default,$94=Default,$95=Default,$96=Default,$97=Default,$98=Default,$99=Default,$100=Default,$101=Default,$102=Default,$103=Default,$104=Default,$105=Default,$106=Default,$107=Default,$108=Default,$109=Default,$110=Default,$111=Default,$112=Default,$113=Default,$114=Default,$115=Default,$116=Default,$117=Default,$118=Default,$119=Default,$120=Default,$121=Default,$122=Default,$123=Default,$124=Default,$125=Default,$126=Default,$127=Default,$128=Default,$129=Default,$130=Default,$131=Default,$132=Default,$133=Default,$134=Default,$135=Default,$136=Default,$137=Default,$138=Default,$139=Default,$140=Default,$141=Default,$142=Default,$143=Default,$144=Default,$145=Default,$146=Default,$147=Default,$148=Default,$149=Default,$150=Default,$151=Default,$152=Default,$153=Default,$154=Default,$155=Default,$156=Default,$157=Default,$158=Default,$159=Default,$160=Default,$161=Default,$162=Default,$163=Default,$164=Default,$165=Default,$166=Default,$167=Default,$168=Default,$169=Default,$170=Default,$171=Default,$172=Default,$173=Default,$174=Default,$175=Default,$176=Default,$177=Default,$178=Default,$179=Default,$180=Default,$181=Default,$182=Default,$183=Default,$184=Default,$185=Default,$186=Default,$187=Default,$188=Default,$189=Default,$190=Default,$191=Default,$192=Default,$193=Default,$194=Default,$195=Default,$196=Default,$197=Default,$198=Default,$199=Default,$200=Default)
    Local $a[@NumParams]
    For $i = 0 To UBound($a)-1
        $a[$i] = Eval($i+1)
    Next
    SomeFunction($a)
EndFunc
Func SomeFunction($array)
    _ArrayDisplay($array)
EndFunc

basically a function to concat strings into an array...

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

That's something like what the _ArrayCreate function did, but with a lot more code.

Func _ArrayCreate($v_0, $v_1 = 0, $v_2 = 0, $v_3 = 0, $v_4 = 0, $v_5 = 0, $v_6 = 0, $v_7 = 0, $v_8 = 0, $v_9 = 0, $v_10 = 0, $v_11 = 0, $v_12 = 0, $v_13 = 0, $v_14 = 0, $v_15 = 0, $v_16 = 0, $v_17 = 0, $v_18 = 0, $v_19 = 0, $v_20 = 0)
    Local $av_Array[21] = [$v_0, $v_1, $v_2, $v_3, $v_4, $v_5, $v_6, $v_7, $v_8, $v_9, $v_10, $v_11, $v_12, $v_13, $v_14, $v_15, $v_16, $v_17, $v_18, $v_19, $v_20]
    ReDim $av_Array[@NumParams]
    Return $av_Array
EndFunc   ;==>_ArrayCreate

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BTW

Another workaround, which can be useful when your Parameters are Strings, is to create a Function that receives 1 string parameter,

and expects that string parameter to contain all the needed values, seperated by some character, for example "|".

Then, inside the function you StringSplit() the Parameter, and get an Array..

Again, it's good for strings.

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...