TomJohn Posted July 12, 2022 Posted July 12, 2022 Hey guys, cant find anything about this. I want to create an empty array in each loop for example: for $i = 0 to Ubound($mylist)-1 <- create array$i[0]-> next
Dan_555 Posted July 12, 2022 Posted July 12, 2022 (edited) #include <Array.au3> While 1 Local $arr[10] _ArrayDisplay ($arr) for $x=0 to 9 $z="" for $y=0 to 10 $z=$z & chr(Random(32,64)) Next $arr[$x]=$z & $x Next _ArrayDisplay ($arr) WEnd That should do it ... additionally you can empty the array with $arr="" after the next Edited July 12, 2022 by Dan_555 Some of my script sourcecode
jchd Posted July 12, 2022 Posted July 12, 2022 Local $array[0] creates an empty 1D array (zero rows). Local $array[0][3] creates an empty 2D array (zero rows of 3 columns). And so on... 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)
TomJohn Posted July 13, 2022 Author Posted July 13, 2022 Ok maybe i messed up the question. I know how i create an array. But i want create a completly new array in each loop. So for example If $value=3 i loop it 3 Times and get $array1, $array2, and $array3 But If my $value=5 i get $array1, $array2, $array3, $array4 and $array5
genius257 Posted July 13, 2022 Posted July 13, 2022 Hi @TomJohn. Something like this? For $i = 1 to 3 Dim $aArray[0] Assign("array"&$i, $aArray) Next ConsoleWrite(VarGetType($array1)&@CRLF) ConsoleWrite(VarGetType($array2)&@CRLF) ConsoleWrite(VarGetType($array3)&@CRLF) TomJohn and pixelsearch 1 1 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
pixelsearch Posted July 13, 2022 Posted July 13, 2022 (edited) Bravo genius257, I like the way you scripted it (the Dim $aArray[0] should be placed before the loop but that's minor) . Imho, your script could find its place in the help file examples, topic Assign. The help file stipulates : Assign ( "varname", "data" [, flag = 0] ) varname : The name of the variable you wish to assign. Cannot be an array element [...] You showed the way to assign it to an array variable name, great Edited April 30, 2023 by pixelsearch nothing important "I think you are searching a bug where there is no bug..."
genius257 Posted July 14, 2022 Posted July 14, 2022 (edited) Hi @pixelsearch . Many thanks for the nice words You are right about the dim within the loop, my bad Just for fun, it is possible with some trickery to assign values to an array element: #include <Array.au3> #include <AutoItConstants.au3> UnknwonVaribleName() AssignExample('x') AssignExample('y') Func UnknwonVaribleName() Local Static $sName = "aArray"&Random(0, 200, 1) If IsDeclared($sName) Then Return $sName Local $aArray = [3, 2, 1] Assign($sName, $aArray, $ASSIGN_FORCEGLOBAL) EndFunc Func AssignExample($vValue) Local $sName = UnknwonVaribleName() _ArrayDisplay(Eval($sName), "before") Assign($sName, ArrayAssign(Eval($sName), $vValue, 1)) _ArrayDisplay(Eval($sName), "after") EndFunc Func ArrayAssign(ByRef $aArray, $vValue, $iIndex1, $iIndex2 = 0, $iIndex3 = 0, $iIndex4 = 0) Switch @NumParams - 2 Case 1 $aArray[$iIndex1] = $vValue Case 2 $aArray[$iIndex1][$iIndex2] = $vValue Case 3 $aArray[$iIndex1][$iIndex2][$iIndex3] = $vValue Case 4 $aArray[$iIndex1][$iIndex2][$iIndex3][$iIndex4] = $vValue EndSwitch Return $aArray EndFunc Now i don't see a good reason to ever do stuff like this, but it is fun to play with restrictions. Edited July 14, 2022 by genius257 typo To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
TomJohn Posted July 14, 2022 Author Posted July 14, 2022 20 hours ago, genius257 said: Hi @TomJohn. Something like this? For $i = 1 to 3 Dim $aArray[0] Assign("array"&$i, $aArray) Next ConsoleWrite(VarGetType($array1)&@CRLF) ConsoleWrite(VarGetType($array2)&@CRLF) ConsoleWrite(VarGetType($array3)&@CRLF) This. This is exaktly what im looking for!
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