Page 99 - Excel Progamming Weekend Crash Course
P. 99

h540629 ch05.qxd  9/2/03  9:33 AM  Page 74




                74                                                          Saturday Morning


               Table 5-3                                                      Continued

               Pattern        Matches                                  Does Not Match
               c?d            cad, cod, cud, c!d                       cook, dad, cd
               #####-####     Any “ZIP plus 4” ZIP code                Anything else
               [!5]####       Any five-digit number not starting with 5  Anything else


                  The final comparison operator is used to compare object references. The Is operator
               returns True if two references refer to the same object:
                  ObjectRef1 Is ObjectRef2
                  You can also use Is to determine if an object reference does not reference anything (con-
               tains the value Nothing):
                  ObjectRef Is Nothing



               Operator Precedence

               With some expressions, there is no doubt as to how it will be evaluated. Other more complex
               expressions, however, can be ambiguous. Look at this expression:

                  12 * 3 + 5
                  If the multiplication is done first, you have 36 + 5 resulting in 41. If the addition is per-
               formed first, you have 12 * 8 resulting in 96. VBA’s rules of operator precedence resolve this
               sort of situation by specifying the order in which operations are carried out. In highest to
               lowest precedence order, they are:

                   Exponentiation (^)
                   Multiplication (*) and division (/)
                   Integer division (\)
                   Modulus (mod)
                   Addition (+) and subtraction (-)
                   String concatenation (&)

                  In the previous example 12 * 3 + 5, the multiplication is performed first and the result
               is 41.

                          When the order of execution is not modified by operator precedence or
                          parentheses, it always proceeds from left to right in the expression.
                   Tip
                  You can modify the order of execution in an expression by using parentheses. Anything
               within parentheses is evaluated first, regardless of operator precedence. Thus,
   94   95   96   97   98   99   100   101   102   103   104