SArr_Reverse() - Reverse the order of elements in a string array

This function is specifically designed to be a METHOD in an object. Objects cannot be passed string arrays because PowerBasic objects are COM objects, and COM objects can't accept string arrays as parameters.

The way to work around this is to use Variants.

In the following function, a variant is used to receive the incoming string array, and a variant is used to return the string array.

Code
    METHOD SArr_Reverse(BYVAL MyArr AS VARIANT) AS VARIANT
        'Purpose
        '   Used to reverse the order of elements in a string array.
        'Parameters
        '   MyArr (Variant String Array) = The array we're working with.
        'Return (Variant String Array)
        '   Returns the specified string array (MyArr) with all elements reversed.
        'Note
        '   This is only designed to work with zero-based arrays.
        '       If the LBOUND() of the array is not zero, this function will fail.
        'Version History
        '   1.0 2010.09.11 Tested by Russ Tanner on PB/CC 5.05.
        '---

        DIM i AS LONG                       'Iterator.
        DIM a() AS STRING : REDIM a(0)      'Source buffer.
        DIM b() AS STRING                   'Destination buffer.

        'Convert the variant string array into a native string array.
        a() = MyArr

        'Create a buffer array with enough elements to hold the original array.
        REDIM b(UBOUND(a))

        'Iterate the original array and transfer elements into the buffer array.
        FOR i = 0 TO UBOUND(a)
            b(UBOUND(a)-i) = a(i)
        NEXT i

        'Now, simply return the new array, which has the elements reversed.
        METHOD = b()

    END METHOD


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)