Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- FUNCky - <b>name:</b> <b>ondo() - execute function/expression <nn> in list</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  Name:     ondo() - execute function/expression <nn> in list
  Usage:    <result> = ondo(<num>,<param1>,<param2>....)
  Params:   string <param1>..<param2>..  - function names to execute
  Returns:  value <result> - value returned by function <nn> in list

 ---------------------------------- Example ---------------------------------

                 @ 10,30 prompt "Edit Records       "
                 @ 11,30 prompt "Delete Records     "
                 @ 12,30 prompt "Append Records     "
                 @ 13,30 prompt "Quit               "

                 menu to mchoice
                 if mchoice = 0
                      byefunc()
                 endif
                 ondo(mchoice,"Efun()","Dfun()","Afun()","byefun()")

            In this case, if the user selects Delete Records, then
            mchoice will equal 2. ondo() will take the value of
            mchoice and will look up the second function that follows
            mchoice. Since Dfun() is the 2nd function in the list
            after mchoice, that function is run. Optionally, you can
            assign the return value of ondo() to a memvar since ondo()
            will return whatever value the function that is run
            returns. As an example, in the example given, if the Dfun()
            returned an integer equal to the record number deleted, then
            using the syntax:

            m1 = ondo(choice,"Efun()","Dfun()","Afun()","byefun()")

            will assign the record number deleted to the memvar m1.

  Note:     Ondo() is the equivalent of a single line case statement.
            You can pass parameters to the functions by including them
            in the function call just as you would call them normally.
            For example, if you wanted to pass the value of mchoice to
            Afun(), you would specify the Afun() parameter as follows:

                 ondo(choice,"Afun(mchoice)")

            If you want to pass a constant, that constant has to be
            enclosed in quotes even inside the quotes that define the
            parameter as a string. This can be done by enclosing the
            constant in single quotes or brackets. As an example, if
            you want to pass the string "test" to Afun(), you would
            code it as follows:

                 ondo(choice,"Afun([test])")

            You can also pass complex function expressions inside ondo().
            Just code the function exactly as you would encode it in your
            program. Make sure that any constant strings are enclosed
            in single quotes, and the entire function expression is
            enclosed in double quotes. You could pass the following
            function declaration to ondo():

                 select A
                 use employee index empname ALIAS EMPLOYEE
                 select B
                 use position index empname ALIAS POSITION
                 set relation to empno into A

                 seek EMPNO

                 @ XX,YY prompts........
                 menu to choice

            ondo(choice,"prnfun(uppe(trim(EMPLOYEE->fname)))")

            In addition to running function <nn> in the list, you
            can have ondo() evaluate expression <nn> in the list. ondo()
            will return the result of the specified expression. For
            example, if you had to evaluate a different expression for
            different operations based on what the user selects you
            would code it normally as follows:

                 @ .. .. prompts .....
                 menu to choice
                 do case
                      case choice = 1
                           mvalue = (13.12 * 30)

                      case choice = 2
                           mvalue = (15.12 * 20)

                      case choice = 3
                           mvalue = (17.12 * 10)

            this entire block can be replaced with the ondo() expression:

            mvalue = ondo(choice,"(13.12*30)","(15.12*20)",;
                           "(17.12*10)")

            You must always remember to include the parenthesis
            in the function name. Unlike achoice(), ondo()
            requires that parenthesis be part of the name
            enclosed in quotes. It is up to the programmer to ensure
            that the value of the first parameter is within the
            correct range for the number of parameters supplied.


See Also: execute()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson