Page 43 - Excel for Scientists and Engineers: Numerical Methods
P. 43

20                                         EXCEL: NUMERICAL METHODS



               corresponding  worksheet  functions  (ABS,  EXP,  INT,  LEN,  LEFT,  MID  AND
               RIGHT,  respectively).  Others,  such as Asc,  Chr and  Sqr, are  spelled a  little
               differently (the corresponding worksheet functions are CODE, CHAR and SQRT,
               respectively)  or  completely  differently  (LCase  and  UCase  correspond  to
               LOWER and UPPER).  These VBA functions are used in exactly the same way
               that they are used in worksheet formulas; they take the same type of arguments
               and return the same type of values.
                   Note  that  although  Excel  has  three  worksheet  functions  that  return
               logarithms (LN returns the natural or base-e logarithm, LOG10 returns the base-
               10 logarithm, and  LOG returns a logarithm to a specified base), VBA has only
               one logarithmic function, Log, that returns the base-e logarithm.  If you need to
               work with base-10 logarithms in your VBA code, use the relationship loglo(a) =
               loG(a)/ lo&( 10).
                    VBA does not provide a function to evaluate n, but you can calculate it in a
               function  by  using  the  expression  4*Atn(l).  Or,  you  can  use  the  worksheet
               function PI(), in the manner described in the following section.

                              Table 2-2.  Some VBA Mathematical Functions
                   Abs          Returns the absolute value of a number.
                   Atn          Returns the arctangent of a number.  The result is an angle
                                in radians.
                   cos          Returns the cosine of an angle in radians.
                   EXP          Returns e raised to a power.
                   Int          Returns the integer part of a number (rounds down).
                   Log          Returns the natural (base-e) logarithm of a number.
                   Rnd          Returns a random number equal to or greater than 0 and
                                less than  1.
                   Sin          Returns the sine of an angle in radians.
                   Sqr          Returns the square root of a number.
                   Tan          Returns the tangent of an angle in radians.


                   The  above  mathematical  functions,  except  for  Rnd,  have  the  syntax
               FuncfionName(argument).  Rnd  takes  no  argument,  but  requires  the  empty
               parentheses.
                   VBA provides functions for working with text; some of the more useful ones
               are  listed  in  Table 2-3.  Most  of these are  identical to Excel's text worksheet
               functions.  If you are unfamiliar with the use of text functions, see the syntax and
               examples in Appendix 1.
   38   39   40   41   42   43   44   45   46   47   48