Ray Posted October 18, 2011 Share Posted October 18, 2011 (edited) For the past two weeks, I've been working on a project that required sifting through directories of files and I decided to write a script to give me a hand with the task. After a few attempts, I just wasn't happy with how long it was taking to complete the tasks. I looked every where I could think of trying to find a few functions that would help speed up my program but had no luck. I decided to try and write a couple myself and although I'm sure they could be greatly improved on, I'm ok with them as they are, at least they have made a difference in performance of my program. I'm posting them here to see if any of you could help me improve them or even just give me pointers on how to code the routines better. Please try them out and let me know. Func _ArrayResize is basically just using ReDim but provides the ability to go from a 1-dimension array to a 2-dimension array and back again to a 1-dimension array. Func _ArrayPack allows for mass deletions of elements/rows from both 1 and 2-dimension arrays. Any feedback would be appreciated. Thank youFunc_ArrayResize-_ArrayPack.au3 Edited October 18, 2011 by Ray Link to comment Share on other sites More sharing options...
Spiff59 Posted October 18, 2011 Share Posted October 18, 2011 This seems to me a more straight-forward route for the pack function: Func _ArrayPack(ByRef $avArray, $iCol = 0) If Not IsArray($avArray) Then Return SetError(1, 0, 0) Local $dims = UBound($avArray, 0), $rows = UBound($avArray, 1), $cols = UBound($avArray, 2) Local $pointer = -1 Switch $dims Case 1 For $r = 0 To $rows - 1 If $avArray[$r] <> "" Then $pointer += 1 $avArray[$pointer] = $avArray[$r] EndIf Next ReDim $avArray[$pointer + 1] Case 2 For $r = 0 To $rows - 1 If $avArray[$r][$iCol] <> "" Then $pointer += 1 For $c = 0 To $cols - 1 $avArray[$pointer][$c] = $avArray[$r][$c] Next EndIf Next ReDim $avArray[$pointer + 1][$cols] Case Else Return SetError(3, 0, 0) EndSwitch Return $avArray EndFunc Link to comment Share on other sites More sharing options...
Ray Posted October 18, 2011 Author Share Posted October 18, 2011 That does look much better, Spiff59. I'll give that a try. Thank you very much for the input. Link to comment Share on other sites More sharing options...
Ray Posted October 19, 2011 Author Share Posted October 19, 2011 The _ArrayPack function included in the attached files of the first post has proven to be faulty. However the code suppied by Spiff59 does the packing task with no problems. It doesn't provided the return code as specified in the original function but is easily modified to do so. Again, thanks Spiff59. Any comments or suggestions concerning the _ArrayResize function from anyone would be welcomed. So far, it is working fine for me. 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