home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / miscprog / wzall / wz002.txt < prev    next >
Encoding:
Text File  |  1991-01-24  |  5.3 KB  |  123 lines

  1.                               INFORMIX SOFTWARE, INC., LENEXA, KS
  2.                         Wingz Technical Support Bulletin Number 002
  3.           
  4.           
  5.           Title:    User-defined Functions
  6.           Date:     December 27, 1988
  7.           
  8.           Hyperscript,  the programming language behind Wingz,  can be 
  9.           utilized in more ways than just automating procedural steps. 
  10.           One  of  Hyperscript's  more powerful  capabilities  is  the 
  11.           ability to create user-defined functions.  While Wingz makes 
  12.           available over 140 worksheet functions, there is going to be 
  13.           someone  who  will  want some function that Wingz  does  not 
  14.           provide.   That  is  where user-defined functions will  come 
  15.           into play.
  16.           
  17.           Following is an example of a user-defined function:
  18.           
  19.           FUNCTION circle(r)
  20.           
  21.           RETURN pi()*r^2
  22.           
  23.           END FUNCTION
  24.           
  25.           In the above example, r is an argument that is passed during 
  26.           the  call to this particular function;  in this case,  it is 
  27.           the radius of the circle in question.   The RETURN statement 
  28.           passes  back  the  result of the expression to  the  calling 
  29.           statement.
  30.           
  31.           Another example:
  32.           
  33.           FUNCTION rect(l,w)
  34.           
  35.           DEFINE area
  36.           
  37.           area = l*w
  38.           RETURN area
  39.           
  40.           END FUNCTION
  41.           
  42.           In this example, a local variable has been defined using the 
  43.           command DEFINE.   By being local,  we mean that the variable 
  44.           will  exist  in  memory only for the life of  the  function.  
  45.           When the function is called, a location in memory is created 
  46.           for  the  variable.   When the function finishes  execution, 
  47.           that  location  in memory is deallocated,  thus erasing  the 
  48.           variable and its contents, making it impossible to reference 
  49.           in  any  sheet or script.   This is quite the opposite of  a 
  50.           global  variable  where,  once  a global variable  has  been 
  51.           defined  and  initialized in a script,  then any  script  or 
  52.           sheet can reference it (the exceptions are variables created 
  53.           in dialog boxes).  
  54.           
  55.           To  use a function that you have defined,  it must first  be 
  56.           loaded into the computer's memory.  This is done via the GET 
  57.           SCRIPT  command.   GET SCRIPT loads the function into memory 
  58.           and  makes  it available to be called by other  scripts  and 
  59.           sheets.   RUN SCRIPT will not load nor execute and function. 
  60.           (To   remove  a  loaded  script,   use  the  REMOVE   SCRIPT 
  61.           "script_name" command entered from the entry bar.)
  62.           
  63.           Once  a  script has been loaded into memory,  you must  then 
  64.           call the script.  This is accomplished in one of three ways:
  65.           
  66.           1)  If  the  function is to be used in a sheet to  return  a 
  67.           value,  you  must  precede the call to the function with  an 
  68.           equal sign ("=") and you must precede the function name with 
  69.           the  name of the file it is defined in (the name of the file 
  70.           you loaded into memory with the GET SCRIPT command) followed 
  71.           by a colon.   For illustrative purposes,  suppose the circle 
  72.           function  defined above was defined in a file called  FUNCS. 
  73.           To  call  this function in a worksheet,  you would  use  the 
  74.           following syntax:
  75.           
  76.           =FUNCS:circle(5)
  77.           
  78.           If  this equation was entered into a cell,  the result would 
  79.           be 78.54.
  80.           
  81.           2)   To reference a function within a script and assign  its 
  82.           return  to a variable is similar in syntax to referencing  a 
  83.           function in a worksheet.  The syntax is as follows:
  84.           
  85.           DEFINE a
  86.           a = FUNCS:circle(5)
  87.           
  88.           These  two  statements  will assign the value 78.54  to  the 
  89.           variable "a" defined in the script.
  90.           
  91.           3)   Suppose  we have the following function defined in  the 
  92.           same  file,  FUNCS,  to  format  a  selected  range  on  the 
  93.           worksheet:
  94.           
  95.           FUNCTION fmt()
  96.           
  97.           TEXT FONT "Bookman"
  98.           TEXT SIZE 14
  99.           TEXT STYLE "BU"
  100.           ALIGN CENTER
  101.           
  102.           END FUNCTION
  103.           
  104.           To call this function, you would use the CALL  command.  The 
  105.           syntax for this is:
  106.           
  107.           CALL FUNCS:fmt()
  108.           
  109.           Calls  to  functions can be very useful in  customizing  the 
  110.           Wingz  environment  and  in modularizing  your  applications 
  111.           developed  with  Hyperscript.   If  you have  a  dialog  box 
  112.           defined in a function,  then you can call it from a menuitem 
  113.           you have added to the Wingz menubar.  This procedure is what 
  114.           Wingz  uses to create the dialog boxes you currently see  in 
  115.           Wingz.
  116.           
  117.           Wingz functions have the following limits:
  118.           
  119.           255 functions per script file
  120.           255 local variables per function
  121.  
  122.           
  123.