= Simple assign

 = (assign)
 Simple assign--binary                           (Assignment)
------------------------------------------------------------------------------
 Syntax

     <idVar> = <exp>

 Type

     All

 Operands

     <idVar> is a valid variable identifier of any storage class,
     including a field variable.  If <idVar> is not visible or does not
     exist, a private variable is created and assigned the result of <exp>.

     <exp> is the expression whose result is assigned to <idVar>.

 Description

     The simple assignment operator (=) assigns a value to a variable.  It is
     identical in operation to the STORE command that initializes a single
     variable and must be specified as a program statement.  The inline
     assignment operator (:=) is like the = operator except that you can
     specify it within expressions.  If you specify the simple assign
     operator (=) within an expression, it is interpreted as the equality (=)
     operator.

     Note:  You cannot initialize a specific variable using the simple
     assign operator (=) in a declaration statement.  Only the inline assign
     (:=) operator can be used for this purpose.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is always
     assumed to be MEMVAR.  At runtime, if no private or public variable
     exists with the specified name, a private variable is created.  To
     assign a field variable with the = operator, you must declare the field
     variable name in a FIELD statement or refer to the field name prefaced
     by the FIELD-> alias or the name of the work area.

 Examples

     .  These examples are valid simple assignment statements:

        nValue = 25
        nNewValue = SQRT(nValue) ** 5
        nOldValue = nValue

     .  In this example, the two lines are equivalent:

        FIELD->CustAge = 20
        REPLACE CustAge WITH 20

See Also: ++ — := = (compound) STORE*

 

:= Inline assign

:=
 Inline assign--binary                           (Assignment)
------------------------------------------------------------------------------
 Syntax

     <idVar> := <exp>

 Type

     All

 Operands

     <idVar> is a valid variable identifier of any storage class,
     including a field variable.  If <idVar> is not visible or does not
     exist, a private variable is created and assigned the result of <exp>.

     <exp> is the expression whose result is assigned to <idVar>.

 Description

     The inline assignment operator (:=) assigns values of any data type to
     variables of any storage class.  The operator evaluates <exp>, assigns
     the resulting value to <idVar>, and returns the resulting value as the
     return value of the operation.  This latter behavior permits multiple
     assignments such as idVar1 := idVar2 := value.  Unlike the simple assign
     operator (=), the inline assignment operator (:=) can be used anywhere
     an expression or constant is allowed, including variable declaration
     statements.  With a variable declaration statement, assignment
     initializes a variable.  Note, however, you cannot declare an array and
     initialize elements within the same program statement.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is always
     assumed to be MEMVAR.  At runtime, if no private or public variable
     exists with the specified name, a private variable is created.  You can
     assign field variables with the := operator by declaring the field
     variable name in a FIELD statement or referring to the field name
     prefaced by the FIELD-> alias or the name of the work area.

 Examples

     .  Several examples of inline assignment follow:

        LOCAL nValue := 10
        //
        IF (dDate := (DATE() - 1000)) = CTOD("12/20/79")
        //
        ? SQRT(nValue := (nValue ** 2))
        //
        cTransNo := cSortNo := (CustId + DTOC(DATE()))

     .  This last example performs multiple assignments using the
        inline assignment operator as you would with the STORE command.  When
        := is used in this way, the assignments are executed from right to
        left.  This feature is particularly useful when you need to store the
        same value to many different fields, possibly in different database
        files.

        CustFile->CustId := TransFile-> ;
           TransNo := (CustId + DTOC(DATE())

See Also: ++ — = (assign) = (compound) STORE*

 

— Decrement

--
 Decrement--unary                                (Mathematical)
------------------------------------------------------------------------------
 Syntax

     --<idVar>       (prefix decrement)
     <idVar>--       (postfix decrement)

 Type

     Date, numeric

 Operands

     <idVar> is any valid CA-Clipper identifier, including a field
     variable.  If <idVar> is a field, you must reference it prefaced with an
     alias or declare it with the FIELD statement.

     In addition, you must initialize <idVar> to a value before performing
     the decrement operation, and it must be either numeric or date data
     type.

 Description

     The decrement operator (--) decreases the value of its operand by one.
     This operator subtracts one from the value of <idVar> and assigns the
     new value to <idVar>.

     The -- operator can appear before or after <idVar>.  Specifying the
     operator before <idVar> decrements and assigns the value before the
     value is used.  This is called prefix notation, and it is the most
     common usage.  Specifying the operator after <idVar> decrements and
     assigns the value after it is used.  This is postfix notation.  Stated
     differently, postfix notation delays the assignment portion of the
     operation until the rest of the expression is evaluated, and prefix
     notation gives the assignment precedence over all other operations in
     the expression.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is always
     assumed to be MEMVAR.  You can assign field variables by declaring the
     field variable name in a FIELD statement or by referring to the field
     name prefaced by the FIELD-> alias or by the name of the work area.

 Examples

     .  In this example of the postfix decrement operator the
        assignment takes place before the original variable is decremented,
        thus the two values are not the same when queried:

        nValue := 1
        nNewValue := nValue--
        ? nNewValue                  // Result:   1
        ? nValue                     // Result:   0

     .  In this example, the prefix decrement operator decreases the
        first operand of the multiplication by one, making its value 9.
        Then, the assignment of this new value to the nValue variable takes
        place before the rest of the expression is evaluated.  Thus, the new
        value is used to perform the multiplication operation, and the result
        of 9 * 9 is 81.

        nValue := 10
        ? --nValue * nValue          // Result:  81
        ? nValue                     // Result:   9

See Also: ++ – := = (compound)

– Subtraction, concatenation

 -
 Subtraction, unary negative, concatenation  (Math, Character)
------------------------------------------------------------------------------
 Syntax

     <nNumber1> - <nNumber2>             (subtraction)
     <dDate1>   - <dDate2>               (subtraction)
     <dDate>    - <nNumber>              (subtraction)
     <cString1> - <cString2>             (concatenation)

 Type

     Character, date, memo, numeric

 Operands

     <nNumber1> is a numeric value to decrement by <nNumber2>.

     <dDate1> is a date value to decrement by <dDate2>.

     <dDate> is a date value to decrement by <nNumber> days.

     <cString2> is a character string to join to the end of
     <cString1> after trimming the trailing blanks from <cString1>.

 Description

     The (-) operator performs different operations depending on the data
     types of the operands:

     .  Unary negative sign (numeric): A numeric expression prefaced
        with the minus (-) operator performs the equivalent of multiplying
        the operand by (-1), returning a negative numeric value.

     .  Binary subtraction (numeric, date): If both operands are
        numeric data type, <nNumber2> is subtracted from <nNumber1> and the
        result is returned as a numeric value.  If both operands are date
        data type, <dDate2> is subtracted from <dDate1> and the result is
        returned as a numeric value representing the number of days between
        the two dates.  If the left operand is date data type and the right
        operand numeric data type, the <nNumber> is subtracted as days from
        <dDate> and a date value is returned.  If the order of operands is
        reversed, a runtime error occurs.

     .  Concatenation (character, memo):  If both operands are
        character data type, <cString2> is joined to <cString1>, returning a
        character string. Trailing blanks are trimmed from <cString1> and
        joined to the end of the return string.

 Examples

     .  These examples illustrate the various forms of the - operator:

        // Binary subtraction (numeric)
        ? 1 - 1                           // Result: 0
        ? 1 - 0                           // Result: 1
        ? 0 - 1                           // Result: -1

        // Binary subtraction (date)

        ? CTOD("12/12/88") - 12         // Result: 11/30/88
        ? 12 - CTOD("12/12/88")         // Result: Runtime error

        // Concatenation (character)
        ? "Hi " - "There" + "*"         // Result: Hithere *

See Also: % * ** + / = (compound)

 

++ Increment

 ++
 Increment--unary                                (Mathematical)
------------------------------------------------------------------------------
 Syntax

     ++<idVar>         (prefix increment)
     <idVar>++         (postfix increment)

 Type

     Date, numeric

 Operands

     <idVar> is any valid Clipper identifier including a field
     variable.  If <idVar> is a field, it must either be prefaced with an
     alias or declared with the FIELD statement.

     The prefix increment can only be performed on an initialized value of
     numeric or date data type.

 Description

     The increment operator (++) increases the value of its operand by one.
     This operator adds one to the value of <idVar> and assigns the new value
     to <idVar>.

     The ++ operator can appear before or after <idVar>.  Specifying the
     operator before <idVar> increments and assigns the value before <idVar>
     is used.  This is called prefix notation, and it is the most common
     usage.  Specifying the operator after <idVar>, postfix notation,
     increments and assigns the value after <idVar> is used.  Stated
     differently, postfix notation delays the assignment portion of the
     operation until the rest of the expression is evaluated, and prefix
     notation gives the assignment precedence over all other operations in
     the expression.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is always
     assumed to be MEMVAR.  You can assign field variables by declaring the
     field variable name in a FIELD statement or referring to the field name
     prefaced by the FIELD-> alias or the name of the work area.

 Examples

     .  This code uses the prefix increment operator in an assignment
        statement.  Therefore, both variables have the same value when
        queried:

        nValue := 0
        nNewValue := ++nValue
        ? nNewValue               // Result:   1
        ? nValue                  // Result:   1

     .  In this example, the postfix increment operator increases the
        first operand of the multiplication operation by one, making its
        value 11; however, the assignment of this new value to the nValue
        variable will not take place until the entire expression is
        evaluated.  Therefore, its value is still 10 when the multiplication
        operation occurs, and the result of 11 * 10 is 110.  Finally, when
        nValue is queried again after the expression is evaluated, the
        postfix increment assignment is reflected in its new value, 11.

        nValue := 10
        ? nValue++ * nValue       // Result: 110
        ? nValue                  // Result:  11

See Also: + — := = (compound)