Results
Username:  
Password:
  > Home
v User Guide
    > Introduction
    > Hello World
    > Flow Control
    v Function Calls
       o Arguments
       o Argument list
       o Absolute arguments
       o Results
       o Context linking
       o Pass by reference
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Function Calls >> Results <=  =>      <  1  >  
Results

Like all variables, the "result" variable is an array too.  You can pass more than one value via the elements of result%function if need to.

In the following example, five result values are returned in one go.  Notes: 1. you can do anything to result%function like you do with other variables without causing a function exit or incurring performance penalty; 2. "{arg%function:function} is the function name, used to access the nameless argument in the calling line.

// Returns sum, first, last, max and min

function give_me_5 {

   var argvar = {arg%function:function};

   if ({#arg%{argvar}} == 0) return;

 

   var result%function:sum = 0;

   var result%function:first = "{arg%{argvar}|shift}";

   var result%function:last = "{arg%{argvar}|pop}";

   var result%function:max = "{result%function:first}";

   var result%function:min = "{result%function:first}";

 

   foreach (arg%{argvar}) {

         var result%function:sum conv="+=:{foreach}";

         if ('{foreach}' > '{result%function:max}')

               var result%function:max = {foreach};

         if ('{foreach}' < '{result%function:min}')

               var result%function:min = {foreach};

   }

}

 

give_me_5 "(array)5,3,2,6,9,7,6,8";

display "{result%give_me_5|list}";

// Output: sum=>'46',first=>'5',last=>'8',max=>'9',min=>'2'

 

Also, two special purpose variables "status%function" and "message%function" are there for you to pass out error code and error message.  As a de facto standard, 0 status and blank message indicate no error.

Following the previous example, you can set status and message before returning.

// Returns sum, first, last, max and min

function give_me_5 {

   var status%function = 1;  // Assume guilty until proven innocent

   var message%function = "argument not specified";

 

   var argvar = {arg%function:function};

   if ({#arg%{argvar}} == 0) return;

 

   var result%function:sum = 0;

   var result%function:first = "{arg%{argvar}|shift}";

   var result%function:last = "{arg%{argvar}|pop}";

   var result%function:max = "{result%function:first}";

   var result%function:min = "{result%function:first}";

 

   foreach (arg%{argvar}) {

         var result%function:sum conv="+=:{foreach}";

         if ('{foreach}' > '{result%function:max}')

               var result%function:max = {foreach};

         if ('{foreach}' < '{result%function:min}')

               var result%function:min = {foreach};

   }

 

   var status%function = 0;

   var message%function = "";

}

 

The last two lines can be replaced by return status=0 message="";

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd