Jump to content

Please take a look at these Functions: _ArrayResize and _ArrayPack


Recommended Posts

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 you


Edited by Ray
Link to comment
Share on other sites

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]
   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]
   ReDim $avArray[$pointer + 1][$cols]
  Case Else
   Return SetError(3, 0, 0)
Return $avArray
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...