Returning an Array for a Function or Event

PowerBuilder .NET allows you to return an array datatype from a function or event.

In versions older than 12, PowerBuilder required you to map an Any datatype whenever a function or event returned an array datatype. You must still do this in PowerBuilder Classic. Although you can also map an Any datatype for an array datatype in PowerBuilder .NET, doing so is neither type-safe nor efficient.

To set an array datatype for a return value:

  1. Open a painter for a PowerBuilder object. To return an array on a new:
    • Event – select the object name from the drop-down list at the upper left of the painter, then select New Event from the second drop-down list.
    • Function – select Functions from the upper left drop-down list.
    Note: You can also add an array datatype on a new function object that you define from the New dialog box.
  2. For Return Type, enter the datatype followed by brackets. For multidimensional arrays, you can add commas inside the brackets.
  3. Complete the remaining prototype fields available for the event or function, and add script for the new method.
    For a function script, include a return value that matches the array datatype you entered in the previous step.
This example shows PowerScript syntax for a function that returns an array of type integer:
         public function integer[] ut_test_array ()
            integer ret[]
            ret = {1, 2}
            return ret
          end function