MaximusCZ Posted October 30 Share Posted October 30 (edited) I read a file into array of arrays Local $programFileArray _FileReadToArray($programFile, $programFileArray, "2", ',') Because its array of arrays, I read it like Dim $pointsToAdjust[0] For $i = 0 To UBound($programFileArray)-1 If UBound($programFileArray[$i]) < 5 Then ContinueLoop ;I dont care lines with less than 5 elements If (StringInStr(($programFileArray[$i])[0], $pointName & " : POINT")) == 0 Then ContinueLoop ;not the line we look for Else _ArrayAdd($pointsToAdjust, $i) ;Add the index of an element to the list to remember ExitLoop EndIf Next Now I wanna edit the array so I can call "_FileWriteFromArray" later with my modified data. I check the value I wanna edit: For $point in $pointsToAdjust $testprogramFileArray = $programFileArray ;So the changes here dont affect next iteration ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ($testprogramFileArray[$point])[7] = ' & ($testprogramFileArray[$point])[7] + 2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console <<-- This reads value and adds 2 to it correctly in console output ($testprogramFileArray[$point])[7] = ($testprogramFileArray[$point])[7] + 2 ;<<-- This fails Next It fails with "C:\__work\AutoitSkripts\__PointMouse_fastSim.au3"(1357,78) : error: Statement cannot be just an expression. ($testprogramFileArray[$point])[7] = ($testprogramFileArray[$point])[7] + 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\__work\AutoitSkripts\__PointMouse_fastSim.au3 - 1 error(s), 0 warning(s) Why exactly? The value inside I can read, why cant I assign it a new value? (The +2 is just illustrative) How would I go about updating that value so I can _FileWriteFromArray Later? Thanks for any help Edited October 30 by MaximusCZ Link to comment Share on other sites More sharing options...
Developers Jos Posted October 30 Developers Share Posted October 30 Why are there brackets in that statement? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Solution Nine Posted October 30 Solution Share Posted October 30 (edited) You just cannot do that the way you wrote. Use something like this: Local $a1 = [1,2,3,4,5] Local $a2 = [5,6,7,8,9,0] Local $a3 = [4,5,6] Local $a = [$a1, $a2, $a3] ConsoleWrite(($a[2])[1] & @CRLF) ArrayAssign ($a[2], 1, 100) ConsoleWrite(($a[2])[1] & @CRLF) Func ArrayAssign(ByRef $arr, $idx, $value) $arr[$idx] = $value EndFunc Edited October 30 by Nine typo “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
MaximusCZ Posted October 30 Author Share Posted October 30 35 minutes ago, Jos said: Why are there brackets in that statement? Because it isnt 2D array, but an array of arrays. just $var[$i][$o] doesnt work here 34 minutes ago, Nine said: You just cannot do that the way you wrote. Use something like this: Local $a1 = [1,2,3,4,5] Local $a2 = [5,6,7,8,9,0] Local $a3 = [4,5,6] Local $a = [$a1, $a2, $a3] ConsoleWrite(($a[2])[1] & @CRLF) ArrayAssign ($a[2], 1, 100) ConsoleWrite(($a[2])[1] & @CRLF) Func ArrayAssign(ByRef $arr, $idx, $value) $arr[$idx] = $value EndFunc Works perfectly, thanks! 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