xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

:=

Inline assignment to a variable.

Syntax

<Variable> := <Expression>

Arguments

<Variable>
<Variable> is the name of a variable of any type.
<Expression>
<Expression> is any valid expression whose result is assigned to <Variable>.

Description

The := operator assigns the value of <Expression> to a variable. It is the preferred assignment operator since it can be used to initialize variables within their declaration statements. This is not permitted with the simple assignment operator "=".

If the variable does not exist when the assignment operation is processed, a PRIVATE variable is automatically created and gets assigned the value of <Expression>.

Info

See also:++, --, = (assignment), = (compound assignment)
Category: Assignment operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the use of the inline assignment
// operator in various situations:

   PROCEDURE Main
      LOCAL dDate  := StoD("20050701") // initializes variables
      LOCAL nMonth := Month( dDate )   // in declaration statement

      nDay := 12                       // creates
      nYear := nPreviousYear := 2000   // PRIVATE variables

      // assignment within expression
      IF (nMonth := Month(dDate)) == 7
         ? "July"
      ENDIF
      ? nMonth                         // result: 7

      // note the removed parentheses and
      // different return value of the expression
      IF nMonth := Month(dDate) == 7
         ? "July"
      ENDIF
      ? nMonth                         // result: .T.
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe