Sign in to follow this  
Followers 0
czardas

Unknown number of parameters

3 posts in this topic

I am aware that this can be done by passing a single array of values as the parameter to a function, but I intend to write some functions which accept an indefinite number of separate integers as parameters. It amounts to the same thing in the end, but the syntax will be different. So here's what I came up with.

#include <Array.au3>

Dim $aParamMagic = _ParamMagic(1,2,3,4,5,6,7,8,9) ; Up to 100 parameters allowed

If @error Then
    MsgBox(0, "Error Code", @error)
Else
    _ArrayDisplay($aParamMagic, "Parameters Passed")
EndIf

Func _ParamMagic($00="",$01="",$02="",$03="",$04="",$05="",$06="",$07="",$08="",$09="", _
    $10="",$11="",$12="",$13="",$14="",$15="",$16="",$17="",$18="",$19="", _
    $20="",$21="",$22="",$23="",$24="",$25="",$26="",$27="",$28="",$29="", _
    $30="",$31="",$32="",$33="",$34="",$35="",$36="",$37="",$38="",$39="", _
    $40="",$41="",$42="",$43="",$44="",$45="",$46="",$47="",$48="",$49="", _
    $50="",$51="",$52="",$53="",$54="",$55="",$56="",$57="",$58="",$59="", _
    $60="",$61="",$62="",$63="",$64="",$65="",$66="",$67="",$68="",$69="", _
    $70="",$71="",$72="",$73="",$74="",$75="",$76="",$77="",$78="",$79="", _
    $80="",$81="",$82="",$83="",$84="",$85="",$86="",$87="",$88="",$89="", _
    $90="",$91="",$92="",$93="",$94="",$95="",$96="",$97="",$98="",$99="")

    Local $aParam[100] = [$00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$10,$11, _
    $12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29, _
    $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47, _
    $48,$49,$50,$51,$52,$53,$54,$55,$56,$57,$58,$59,$60,$61,$62,$63,$64,$65, _
    $66,$67,$68,$69,$70,$71,$72,$73,$74,$75,$76,$77,$78,$79,$80,$81,$82,$83, _
    $84,$85,$86,$87,$88,$89,$90,$91,$92,$93,$94,$95,$96,$97,$98,$99]

    For $i = 0 To 99 ; See how many parameters were passed to the func
        If IsString($aParam[$i]) Then ; The first non integer occurs
            ExitLoop
        ElseIf Not IsInt($aParam[$i]) Then
            Return SetError(1, 0, 0)
        EndIf
    Next
    If $i = 0 Then Return SetError(2, 0, 0) ; No valid parameters
    ReDim $aParam[$i] ; Array only needs to contain valid parameters

    ; Do stuff here
    Return $aParam ; Example return variable
EndFunc

Is there another way to do this with AutoIt? The problem is that the code is a bit bulky.

Share this post


Link to post
Share on other sites



Look at @NumParams and #forceref for another way of doing it. You'll also get a good idea of how this is done in WinHTTP.au3. Plus, if the 'bulky' thing is an issue then go with the array option, otherwise this is as good as it gets as far as I know.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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: 04/09/2015

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks guiness. @NumParams was the macro that I had forgotten about. That was exactly the response I was looking for. :D

Edited by czardas

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Jefrey
      By Jefrey
      I've ported these two functions from PHP to AU3 to work with URLs.
      Made them for those who work with libraries like HTTP.au3 (not the one I coded), that needs passing the server domain, path, etc., instead of the full URL.
      Grab the lib here.
      ParseURL( $sURL )
      Parses the URL and splits it into defined parts. Returns an array:
      [0] = Full URL (same as $sURL) [1] = Protocol (i.e.: http, https, ftp, ws...) [2] = Domain [3] = Port (or null if not specified) [4] = Path (or null if not specified) [5] = Query string (everything after the ? - or null if not specified) Example:
      $aExample = ParseURL("https://google.com:8080/?name=doe") MsgBox(0, "Test", "URL: " & $aExample[0] & @CRLF & _ "Protocol: " & $aExample[1] & @CRLF & _ "Domain: " & $aExample[2] & @CRLF & _ "Port: " & $aExample[3] & @CRLF & _ "Path: " & $aExample[4] & @CRLF & _ "Query string: " & $aExample[5])  
      ParseStr( $sStr )
      Parses a query string (similar to the [5] of the previous function) and returns a multidimensional array, where:
      [0][0] = number of variables found [0][1] = ununsed [1][0] = key name of the first variable [1][1] = first variable value (already URL decoded) [n][0] = key name of the nth variable [n][1] = nth variable value (already URL decoded) Example:
      include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib _ArrayDisplay(ParseStr("foo=bar&test=lol%20123")) #cs Result is: [0][0] = 2 [0][1] = ununsed [1][0] = foo [1][1] = bar [2][0] = test [2][1] = lol 123 #ce Feel free to fork!
    • Eddi96
      By Eddi96
      Hello guys!
      #include <Array.au3> #include <File.au3> $iBenutzername = $Var_cmdline ; I need this to be the variable given as a parameter. ; I've read alot about CmdLine but can't think of a way to define a variable with it ; I hope you have an Idea on how to do it! Much love <3 Global $sFile = "C:\GTScript\query.txt" Global $aUsers _FileReadToArray($sFile, $aUsers, $FRTA_NOCOUNT) _ArrayColInsert($aUsers, 1) _ArrayColInsert($aUsers, 1) _ArrayColInsert($aUsers, 1) _ArrayColInsert($aUsers, 1) _ArrayColInsert($aUsers, 1) _ArrayColInsert($aUsers, 1) For $i = 0 To UBound($aUsers) - 1 $aSplit = StringRegExp($aUsers[$i][0], "(\S+)", $STR_REGEXPARRAYGLOBALMATCH) For $j = 0 To UBound($aSplit)-1 $aUsers[$i][$j] =$aSplit[$j] Next $aUsers[$i][0]=StringReplace($aUsers[$i][0],'>','') Next $sUser=$iBenutzername Func _FindUserID($aArray,$sSearch) Local $iRow=_ArraySearch($aArray,$sUser) If @error Then Return SetError(@error,-1,'') Local $sID=$aArray[$iRow][2] Return SetError(0,$iRow,$sID) EndFunc MsgBox(64,'Searcher UserID '&$sUser,_FindUserID($aUsers,$sUser))  
    • Skysnake
      By Skysnake
      Hi Everyone
      I want to have a GUI, but which will accept command line options on launch.
      So, the commanline would look something like
      myAPP.EXE -bigfont -bigicon
      where myAPP.EXE would be the name of the AutoIt EXE, and the -bigfont & -bigicon items represent optional command line parameters with which the EXE starts.
      I am not looking at creating a CUI.  This is GUI, but with startup command line parameters.  These command line parameters would only be read once, during start up of the EXE.
      I have searched the forum, no luck.  What I did find was this commented by Water: https://www.autoitscript.com/forum/topic/138754-adding-command-line-parameter/
      Should I start the GUI EXE as normal, and then first possible opportunity read the command line? Is that the way to go?
      Thanks in advance
    • trdunsworth
      By trdunsworth
      I'm working on a program with a colleague. He wants to create a function which takes 3 parameters and then loop through two arrays which I think we can do well enough. However, we want this to be attached to a GUI form we've built so when the user clicks a button, it will invoke the function which then takes the local variables as the parameters for the function and executes it.
      I know that GUICtrlSetOnEvent can't take parameters, but is there a way to get around this and make this work?
    • wakillon
      By wakillon
      Each time I want try a Command Line Tool I don't remember his switchs !

      So I have made this little utility :

      Get command line parameters Utility v1.0.2.3




      The difficulty is they don't answer the same way or not at all !
      Script start by trying common switches by 2 ways and leaves you try manually after.
      You also have the possibility to use an embeded Dos Prompt instead of the edit box.
      In all cases you can create a text file for save infos.
      Type "ESC" for quit at any time.
      A first run compiled is needed for install a contextual menu for exefile.

      As usual externals files are downloaded at first execution.
      See Tray menu for options.

      Previous downloads : 628

      Update 2012-06-30

      Source : GetCommandLineParameters v1.0.2.3.au3
      executable : GetCommandLineParameters.exe.html
      (Once this html file downloaded, double click on it for start the download)
       
      Sure it will help you !