| xHarbour Reference Documentation > Operator Reference |
![]() |
![]() |
![]() |
Inline assignment to a variable.
<Variable> := <Expression>
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>.
| See also: | ++, --, = (assignment), = (compound assignment) |
| Category: | Assignment operators |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com