Page 195 - Open Soource Technologies 304.indd
P. 195

Unit 8: Understanding Function and Procedure


               End function
               The saying “Less is more.” is displayed in the text box.

               8.4 Comparing Function Procedures with Sub Procedures

               Function Procedures differ from Sub Procedures in the way they are accessed. Sub Procedures are
               invoked with call statements, whereas function are invoked by placing them where you would
               otherwise expect to find a literal, variable, or expression. Unlike a Function Procedures, a Sub
               Procedures can’t be used in an expression.
               Function Procedures can perform the same tasks as Sub Procedures. For instance, they can request
               input and display text. However, Function Procedures are primarily used to calculate a single
               value. Normally, Sub Procedures are used to carry out other tasks.


                              The Sub Procedures considered in this book terminate only when End Sub is
                              reached. On the other hand, Function Procedures terminate as soon as the first
                              Return statement is executed. For instance, if a Return statement is followed
                              by a sequence of statements and the Return statement is executed, then the
                              sequence of statements will not be executed.


               8.5 Collapsing a Procedures with a Region Directive

               A group of Procedures or class-level variables can be collapsed behind a captioned rectangle. This
               task is carried out with a so-called Region directive. To specify a region, precede the code to be
               collapsed with a line of the form
               #Region “Text to be displayed in the rectangle”.
               and follow the code with the line
               #End Region


























                                           Figure 8.1(a): Region Directives.




                                      LOVELY PROFESSIONAL UNIVERSITY                        189
   190   191   192   193   194   195   196   197   198   199   200