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

16                                         EXCEL: NUMERICAL METHODS


                   K=K+1

               which, in the second example, says "Store, in the memory location to which the
               user has assigned the label 'K, the value corresponding to the expression K + 1 .I'
               Operators

                   VBA  operators  include  the  arithmetic  operators  (+,  -,  *,  /,  "),  the  text
               concatenation operator (a), the comparison operators (=,  c, >,  c=, >=,  c>) and
               the logical operators (And, Or, Not)

               Variables
                   Variables are the names you create to indicate the storage locations of values
               or references.  There are a few rules for naming variables or arguments:
                    You  can't  use  any  of  the  VBA  reserved  words,  such  as  Formula,
                    Function, Range or Value.
                    The first character must be a letter.
                    A name cannot contain a space or a period.
                    The characters %,  $,  #,  !, & cannot be embedded in  a name.  If one of
                    these  characters  is  the  last character of  a variable name,  the  character
                    serves as a type-declaration character (see later).
                    You can use upper- and lowercase letters.  If you declare a variable type
                    by using the Dim statement (see "VBA Data Types'' later in this chapter),
                    the capitalization of the variable name will be "fixed" - no matter how
                    you  type  it  in  the  procedure,  the  variable  name  will  revert  to  the
                    capitalization as originally declared.  In contrast, if you have not declared
                    a variable by using Dim, changing the case of a variable name in any line
                    of code (e.g., from formulastring to Formulastring) will cause all instances
                    of the old form of the variable to change to the new form.
                   You should make variable names as descriptive as possible, but avoid overly
               long names which are tedious to type.  You can use the underscore character to
               indicate a space between words (e.g., formula-string).  You can't use a period to
               indicate a space, since VBA reserves the period character for use with objects.
               The most  popular  form  for  variable  names  uses  upper-  and  lowercase  letters
               (e.g., FormulaString).
                   Long  variable  names  like  Formulastring  provide  valuable  self-
               documentation;  months  later,  if  you  examine  your  code  in  order  to  make
               changes, you'll probably be more able to understand it if you used (for example)
               Formulastring as a variable name instead of F.  But typing long variable names is
               time-consuming and prone to errors.  I like to use short names like F when I'm
               developing the code.  Once I'm done, I use the Visual Basic Editor's Replace ...
               menu command to convert all those F's to Formulastring.
   34   35   36   37   38   39   40   41   42   43   44