gcue Posted July 11, 2021 Share Posted July 11, 2021 hello world i am using this example to work off it works great ONLY when column 0 is part of $ColumnNumbersToKeep but get this error if i add another column Quote Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Here is the working/not working sample #include <Array.au3> Local $avArray[5][10] = [ _ ["BOB", "Tom", "Dave", "Jane", "Pat", "Billy", "Tim", "Paul", "Mark", "Barry"], _ ["Lucy", "Mick", "Gary", "Sean", "Claire", "Peter", "janet", "Ken", "Ness", "Ida"]] _ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()") ;~ $ColumnNumbersToKeep = "0,1,6" $ColumnNumbersToKeep = "1,6" $test = ArrayCropColumns($avArray, $ColumnNumbersToKeep) Debug($test) Func ArrayCropColumns($array, $columns) $aColumnsToRetain = StringSplit($columns, ",", 2) _ArraySort($aColumnsToRetain, 1) $counter = 0 For $i = UBound($array, 2) -1 To 0 Step -1 If $i <> $aColumnsToRetain[$counter] Then _ArrayColDelete($array, $i) Else $counter += 1 EndIf Next Return $array EndFunc ;==>ArrayCropColumns Seems to crash when there are 3 columns left - cant seem to delete the next column Any ideas? Link to comment Share on other sites More sharing options...
TheXman Posted July 11, 2021 Share Posted July 11, 2021 (edited) Try changing the following line: $counter += 1 to: If $counter < UBound($aColumnsToRetain) - 1 Then $counter += 1 $counter is being used as an array index. Since you are manually incrementing that index inside your loop, you want to make sure that you don't increment that index if it will exceed the bounds of the array. Which will then, given the logic of the function, delete all remaining columns (which is what you want). Edited July 11, 2021 by TheXman Added explanation CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein Link to comment Share on other sites More sharing options...
gcue Posted July 11, 2021 Author Share Posted July 11, 2021 that worked!! thank you!!! 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