= Compound assignment

 


 = (compound assign)
 Compound assignment--binary                     (Assignment)
------------------------------------------------------------------------------
 Syntax

     <idVar>  += <cString>         (concatenation)
     <idVar>  += <nNumber>         (addition)
     <idVar>  -= <cString>         (concatenation)
     <idVar>  -= <nNumber>         (subtraction)
     <idVar>  -= <dDate>           (subtraction)
     <idVar>  *= <nNumber>         (multiplication)
     <idVar>  /= <nNumber>         (division)
     <idVar>  %= <nNumber>         (modulus)
     <idVar>  ^= <nNumber>         (exponentiation)

 Type

     Character, date, memo, numeric

 Operands

     <idVar> is a variable identifier of any storage class, including a
     field variable.  The variable must be initialized to a value before
     performing the operation.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is 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.

     <cString> is the character string used in the operation with
     <idVar>.

     <nNumber> is the numeric expression used in the operation with
     <idVar>.

     <dDate> is the date value used in the operation with <idVar>.

 Description

     In addition to the simple and inline assignment operators (= and :=),
     there are a series of compound assignment operators that perform an
     operation then assign a value.  They have the form:

     <idVar> <operator>= <exp>

     Each compound assignment expression is equivalent to the assignment
     expression:

     <idVar> := ( <idVar> <operator> <exp> )

     For each data type that supports an operator, the compound assignment
     operator performs the same operation before performing the assignment
     operation.  The  following table details all of the compound operators:

     Compound Operators
     ------------------------------------------------------------------------
     Operator     Defined as     Operations
     ------------------------------------------------------------------------
     a += b       a := (a + b)   concatenation, addition
     a -= b       a := (a - b)   concatenation, subtraction
     a *= b       a := (a * b)   multiplication
     a /= b       a := (a / b)   division
     a %= b       a := (a % b)   modulus
     a ^= b       a := (a ^ b)   exponentiation
     ------------------------------------------------------------------------

     Note:  The exponentiation operator (**) does not have a
     corresponding compound assignment operator.  The exponentiation compound
     assignment operator is ^=.

     Since the compound assignment operators are based on the inline
     assignment  operator (:=), the operation returns the result of its
     operation as the value of the expression.  This means you can use these
     operators within expressions just like the inline assignment operator
     (:=).

 Examples

     .  These examples use the compound addition and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello"
        ? cString += " there"           // Result: "Hello there"

        // Date (addition)
        LOCAL dDate := CTOD("12/12/90")
        dDate += 12                     // Result: 12/24/90

        // Numeric (addition)
        LOCAL nValue := 10
        ? SQRT(nValue += 15)            // Result:  5.00
        ? nValue                        // Result: 25.00

     .  These examples use the compound subtraction and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello   "
        ? cString -= "There"            // Result: HelloThere

        // Date (subtraction)
        LOCAL dDate := CTOD("12/24/90")
        dDate -= 12                     // Result: 12/12/90

        // Numeric (subtraction)
        LOCAL nValue := 10
        ? newValue := (nValue -= 5) ** 2       // Result: 25
        ? nValue                               // Result:  5

     .  This example uses the compound multiplication assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue *= 5) + 100      // Result: 150
        ? nValue                               // Result:  50

     .  This example uses the compound division assignment operator:

        LOCAL nValue := 10
        ? newValue := (nValue /= 5) + 100      // Result: 102.00
        ? nValue                               // Result:   2.00

     .  This example uses the compound modulus assignment operator:

     LOCAL nValue := 10
        ? newValue := (nValue %= 4) * 100      // Result: 200.00

        ? nValue                               // Result:   2.00

     .  This example uses the compound exponentiation assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue ^= 3) + 50       // Result: 1050.00
        ? nValue                               // Result: 1000.00

See Also: % * ** + ++ – — / :=

= 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*