REQUIRES MSExcel 2010 or higher
Trying to do anything complex with VBA arrays is like banging your head on a wall but without that satisfying feeling when you stop. Because of this, I created this class to do the nifty stuff I can do MUCH EASIER with arrays in Perl (mostly).
This object takes a string of values and treats them as an array. If you're using numbers that are more complicated than a double, then this object probably won't work for you. Integers and Longs should be fine. As always, test out your worst case scenario before committing to someone's code.
NOTE: Read the instructions! Early binding is mandatory with this class object.
NOTE: The instructions folder has full explanations and examples for each of these.
Here are the public methods you can access:
objArray.CountElements
=> This is a 1-based number of the elements in the list. If there are five items in the list, this returns the number 5.
objArray.Delimeter
=> Define what character separates the items in the list. Default is a comma.
objArray.Element(n)
=> This returns a string with the contents of the element at position N.
objArray.Edit(n) = string
=> This updates the contents of the element at position N.
objArray.ForceUnique
=> Turn this on and you will only be able to add unique values to the array.
objArray.ForceValue
=> Turn this on and you will not be able to add a null value to the array.
objArray.Grep([regex pattern])
=> Gather a list of items from the array but don't change the original array.
objArray.IndexOf([string])
=> This returns a zero-based index number for the specified items position in the list.
objArray.IndexOfRegex([string])
=> This returns a zero-based index number for the first item matching the pattern.
objArray.Join differentObjArray
=> COmbine two array objects.
objArray.LastIndex
=> This returns the index number of the last element in the list. Equivalent to UBound and effectively the same as CountRemaining. I just added this for clarity.
objArray.Pop
=> This will return a string with the last item in the list and that item will be removed from the list, thus shortening the list.
objArray.Push
=> This will add an item to the back end of the list, thus increasing the size of the list.
objArray.Remove([index])
=> This will remove the item at this index position and shorten the list by one item.
objArray.Reverse
=> This reverses the order of the items in the list.
objArray.SetArray VBAArray
=> This is how you populate the array class with an existing VBA array.
objArray.SetArrayFromRange [range object]
=> This is how you add items from a worksheet column.
objArray.SetArrayFromString [string]
=> This is how you add a string of items to the array.
objArray.Shift
=> This will return a string with the first item in the list and that item will be removed from the list, thus shortening the list.
objArray.Slice([regex pattern OR index], [limit items])
=> Gather a list of items from the array AND remove them from the original array.
objArray.SortAscending
=> This sorts the items in the list ascabetically from lowest to highest.
objArray.SortAsNumbers = [boolean]
Force the sort to treat the array items as number values instead of string characters.
objArray.Splice([index], [new content])
=> Insert one list into another at the specified position.
objArray.Unshift
=> This will add an item to the front end of the list, thus increasing the size of the list.
objArray.raw
=> This is used for debugging. It just returns the array as a string separated by the delimeter.