Imbuter2000 Posted February 26, 2013 Share Posted February 26, 2013 is there a way to pass an array to a function directly like function(["one","two","three"])? In some cases I don't have to use the array outside the the function so I would like to avoid to do an array declaration before calling the function: local $array = ["one","two","three"] function($array) Link to comment Share on other sites More sharing options...
PhoenixXL Posted February 26, 2013 Share Posted February 26, 2013 No, I guess Autoit doesnt support that, why not pass the array and then check the values using a For Loop My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
johnmcloud Posted February 26, 2013 Share Posted February 26, 2013 (edited) Like this? #include <Array.au3> ; For ArrayDisplay Dim $aArray[3]=["1", "2", "3"] $aString =_ArrayToString($aArray, "|") $aSplit = StringSplit($aString, "|") _MyFunc($aArray, "Test") Func _MyFunc($array, $Par2 = "") _ArrayDisplay($array,"") MsgBox(0, 0, $array[0]) MsgBox(0, 0, $Par2) EndFunc Edited February 26, 2013 by johnmcloud Link to comment Share on other sites More sharing options...
jchd Posted February 26, 2013 Share Posted February 26, 2013 Two things: Dim should regarded as obsolescent. Prefer using Local or Global depending on requirements. Arrays can be costly to copy (AutoIt uses copy on write but anyway). Pass arrays ByRef (see help). Recommended option: use the Const modifier as appropriate. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Nessie Posted February 26, 2013 Share Posted February 26, 2013 is there a way to pass an array to a function directly like function(["one","two","three"])? In some cases I don't have to use the array outside the the function so I would like to avoid to do an array declaration before calling the function: local $array = ["one","two","three"] function($array) Maybe ByRef ? From the helpfile: expandcollapse popupExample1() Example2() ; example1 Func Example1() ; Sample script with three user-defined functions ; Notice the use of variables, ByRef, and Return Local $foo = 2 Local $bar = 5 MsgBox(0, "Today is " & today(), "$foo equals " & $foo) swap($foo, $bar) MsgBox(0, "After swapping $foo and $bar", "$foo now contains " & $foo) MsgBox(0, "Finally", "The larger of 3 and 4 is " & max(3, 4)) EndFunc ;==>Example1 Func swap(ByRef $a, ByRef $b) ;swap the contents of two variables Local $t $t = $a $a = $b $b = $t EndFunc ;==>swap Func today() ;Return the current date in mm/dd/yyyy form Return (@MON & "/" & @MDAY & "/" & @YEAR) EndFunc ;==>today Func max($x, $y) ;Return the larger of two numbers If $x > $y Then Return $x Else Return $y EndIf EndFunc ;==>max ;End of sample script 1 ; example2 Func Example2() ; Sample scriptusing @NumParams macro Test_Numparams(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) EndFunc ;==>Example2 Func Test_Numparams($v1 = 0, $v2 = 0, $v3 = 0, $v4 = 0, $v5 = 0, $v6 = 0, $v7 = 0, $v8 = 0, $v9 = 0, _ $v10 = 0, $v11 = 0, $v12 = 0, $v13 = 0, $v14 = 0, $v15 = 0, $v16 = 0, $v17 = 0, $v18 = 0, $v19 = 0) #forceref $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v11, $v12, $v13, $v14, $v15, $v16, $v17, $v18, $v19 Local $val For $i = 1 To @NumParams $val &= Eval("v" & $i) & " " Next MsgBox(0, "@NumParams example", "@NumParams =" & @NumParams & @CRLF & @CRLF & $val) EndFunc ;==>Test_Numparams My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
JohnOne Posted February 26, 2013 Share Posted February 26, 2013 #include <Array.au3> local $array = '"one","two","three"' function($array) Func function($a) $array = StringSplit($a,",",3) _ArrayDisplay($array) EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kylomas Posted February 26, 2013 Share Posted February 26, 2013 (edited) imbuter2000, I would like to avoid to do an array declaration before calling the function: Why? If you explain your purpose there may be other alternatives. kylomas edit: additional info This #include <array.au3> _1('123') func _1($prm) local $array = stringsplit($prm,'') _arraydisplay($array) endfunc and/or variations of what J1 posted are as close as you are likely to get. Edited February 26, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jaberwacky Posted February 27, 2013 Share Posted February 27, 2013 If the arguments will never change then here is a way (no pun intended):Func my_awesome_function() Local Const $my_awesome_array[3] = [1, 2, 3] ; do things EndFunc Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now