Navigation:  Reference > Commands >

User Defined Function

Print this Topic Previous pageReturn to chapter overviewNext page


This is the command that defines a User Defined Function, or UDF.  A UDF may be used in any situation that would allow a regular (standard) function.  Some options in some commands require that a UDF be used.



FUNC sacRequired - This is the name you give to this function.  It is a special alpha constant.    It may be up to 32 characters long.  It must not be the same as any line label used anywhere else in the program.


function_parameters - fn/v1,fn/v2,...,fn/vx The values, if any, being passed to the UDF.  A maximum of 20 fields may be specified.  The field names are separated with commas.




You must include the compiler directive #UDX before the first user defined function is referenced in the program.  All functions end with the command RET (Return).  You may return a single value of any type, including an expression.  Fields within the UDF are not automatically local unless you use the #PROC/#ENDPROC compiler directives and DEFINE the fields as local.  Through this process the UDF may be made reentrant.


Any legal TAS Professional command, EXCEPT CHAIN, may be used in conjunction with a UDF.


NOTE:  You must not execute a CHAIN command from within a UDF.  If you do, the program will not return to the proper location, and you will probably get an AV (Access Violation).





//test UDF





define x type n



  x = user_func(1,3,'A')

  msg 'X: '+x




define y,z,a type n

define do type a size 1

func user_func y,z,do

  if do = 'A'

       a = y+z

  else_if do = 'S'

       a = y-z

  else_if do = 'M'

       a = y*z

  else_if do = 'D'

       a = y/z


  ret a



The above is a complete program.  The result, once compiled and run, would be:





Page url: