• No results found

SET EXACT

In document xHarbour Language Reference Guide (Page 42-54)

Comparison rules

SET EXACT

For character comparisons, the less than operator takes the SET EXACT setting into account. With SET EXACT OFF, characters are compared up to the length of the right operand. With SET EXACT ON, characters are compared up to the length of th e left operand and trailing blank spaces are ignored.

Info

See also: $,>,<=,<> != #,= (comparison),==,>=,SET EXACT Category: Comparison operators,Operators

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example demonstrates the result of the "<" operator.

PROCEDURE Main

? "A" < "Z" // result: .T.

? "a" < "Z" // result: .F.

? CToD("12/28/2005") < CToD("12/31/2005") // result: .T.

? .T. < .F. // result: .F.

<

? 2 < 1 // result: .F.

SET EXACT OFF

? "a" < "a " // result: .T.

SET EXACT ON

? "a" < "a " // result: .F.

RETURN

<<

<<

Left-shift operator (binary): shifts bits to the left.

Syntax

<nNumber1> << <nNumber2>

Arguments

<nNumber1>

<nNumber1> is a numeric value whose bits are shifted to the left.

<nNumber2>

<nNumber2> is a number indicating how many places the bits are shifted to the left.

Description

The << operator accesses individual bits in the left operand and shifts them to the left as many times as specified with the right operand. Both operands are always treated as integer values. If an operand has a decimal fraction, it is truncated prior to the operation.

A shift operation involves all bits of the left operand. When the bits are shifted one place to the left, the highest bit is discarded and the lowest bit is set to 0. A numeric value has 32 bits on a 32 bit operating system.

Shifting a value to the left is equivalent with multiplying <nNumber1> by 2 raised to the power of

<nNumber2>.

Info

See also: >>,HB_BitShift()

Category: Bitwise operators,Operators,xHarbour extensions

LIB: xhb.lib

DLL: xhbdll.dll

Example

// This example shifts the bits of the value 52 two places to // the left so the value becomes 208.

PROCEDURE Main

nValue := 52 // binary: 00110100

? nValue << 2 // binary: 11010000 (value = 208)

? 52 * 2 ^ 2 // result: 208

RETURN

<=

<=

Less than or equal operator (binary): compares the size of two values.

Syntax

<Expression1> <= <Expression2>

Arguments

<Expression1>

The values of <Expression1> and <Expression2> must have the same data type and are compared.

Description

The "less than or equal" operator compares two values of the same data type. It returns .T. (true) when the left operand is smaller than or equal to the right operand, otherwise the return value is .F. (false).

Only the simple data types Character, Data, Logic, Memo and Numeric can be compared. The complex data types Array, Code block, Hash, Object and the value NIL cannot be used with the "less than or equal" operator.

Comparison rules

Data type Comparison

Character The comparison is based on the ASCII value of the characters.

Date The comparison is based on the underlying date value.

Logical False (.F.) is smaller than true (.T.).

Memo Same as Character data type.

Numeric Comparison is based on the value of the numerics.

SET EXACT

For character comparisons, the "less than or equal" operator takes the SET EXACT setting into account. With SET EXACT OFF, characters are compared up to the length of the right operand. With SET EXACT ON, characters are compared up to the length of the left operand and trailing blank spaces are ignored.

Info

See also: $,<,<> != #,= (comparison),==,>,>=,SET EXACT Category: Comparison operators,Operators

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example demonstrates the result of the "<=" operator.

PROCEDURE Main

? "A" <= "Z" // result: .T.

? "a" <= "Z" // result: .F.

<=

? .T. <= .F. // result: .F.

? 2 <= 1 // result: .F.

SET EXACT OFF

? "a" <= "a " // result: .T.

? "a " <= "a" // result: .T.

? "" <= "a" // result: .T.

? "a" <= "" // result: .T.

SET EXACT ON

? "a" <= "a " // result: .T.

? "a " <= "a" // result: .T.

? "" <= "a" // result: .T.

? "a" <= "" // result: .F.

RETURN

<> != #

<> != #

Not equal operator (binary): compares two values for inequality.

Syntax

<Expression1> <> <Expresson2>

<Expression1> != <Expresson2>

<Expression1> # <Expresson2>

Arguments

<Expression>

The values of <Expression1> and <Expression2> must have the same data type or can be NIL, and are compared.

Description

The "not equal" operator compares two values of the same data type or NIL. It returns .T. (true) when the left operand has not the same value as the right operand, otherwise the return value is .F. (false).

Only the simple data types Character, Date, Logic, Memo, Numeric and the value NIL can be

compared. The complex data types Array, Code block and Object cannot be used with the "not equal"

operator.

Comparison rules

Data type Comparison

Character The comparison is based on the ASCII value of the characters.

Date The comparison is based on the underlying date value.

Logical False (.F.) is smaller than true (.T.).

Memo Same as Character data type.

Numeric Comparison is based on the value of the numerics.

NIL NIL is equal to NIL and not equal to any other data type.

SET EXACT

For character comparisons, the "not equal" operator takes the SET EXACT setting into account. With SET EXACT OFF, characters are compared up to the length of the right operand. With SET EXACT ON, characters are compared up to the length of the left operand and trailing blank spaces are ignored.

Info

See also: $,<,<=,= (comparison),==,>,>=,SET EXACT Category: Comparison operators,Operators

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example demonstrates the result of the "<>" operator.

PROCEDURE Main

<> != #

? "ABCDE" <> "ABC" // result: .T.

? "ABC" <> "" // result: .T.

? "" <> "ABC" // result: .T.

SET EXACT OFF

? "ABC" <> "ABCDE" // result: .T.

? "ABCDE" <> "ABC" // result: .F.

? "ABC" <> "" // result: .F.

? "" <> "ABC" // result: .T.

? CToD("12/28/2005") <> CToD("12/31/2005") // result: .T.

? NIL <> NIL // result: .F.

? 2 <> 1 // result: .T.

RETURN

<|| >

<|| >

Extended literal code block.

Syntax

<| [<params,...>] | <programcode> >

Arguments

<params,...>

This is an optional comma separated list of parameter names declared for use inside the extended code block. Code block parameters are only visible within the code block and must be placed between the || delimiters.

<programcode>

<programcode> is any kind of program code which is also allowed within the body of a FUNCTION, except for the declaration of STATICvariables.

Description

Extended literal code blocks are created in program code using the <|| > characters. They can be used in the same way asregular code blocksbut have the advantage that <programcode> can include any statements allowed in the body of a function. This includes statements spanning across multiple lines, such as loops (DO WHILE,FORandFOR EACH), branching (DO CASEandSWITCH), error handling (BEGIN SEQUENCEandTRY...CATCH).

Even the declaration ofLOCALvariables within an extended code block is supported. Only STATIC variables cannot be declared.

The program code, embedded within an extended code block, is executed by passing the code block to theEval()function. Arguments passed to this function are passed on to the code block and are received by the code block parameters. The expressions and statements in the code block are then executed from left to right, or top to bottom, respectively. The return value of the code block must be specified with theRETURNstatement.

Info

See also: {|| },AEval(),AScan(),ASort(),DbEval(),Eval(),HEval(),LOCAL Category: Indirect execution,Operators,Special operators,xHarbour extensions

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example demonstrates the creation of an extended code block as a // return value of function ConversionBlock(). The code block converts // values to character strings. Note that the code block calls itself // recursively within the FOR EACH loop.

PROCEDURE Main

LOCAL bBlock, lLogic:= .T., nNumber:= 1.23456, aArray := Directory() bBlock := ConversionBlock()

<|| >

? Eval( bBlock, aArray )

? Eval( bBlock, lLogic )

? Eval( bBlock, nNumber )

? Eval( bBlock, GetNew() )

? Eval( bBlock, bBLock ) RETURN

FUNCTION ConversionBlock() LOCAL bBlock

bBlock := <| xValue |

LOCAL cType := Valtype( xValue ) LOCAL cValue, xElem

SWITCH cType CASE "A"

cValue := "{"

FOR EACH xElem IN xValue

cValue += Eval( bBlock, xElem ) + ","

NEXT

cValue[-1] := "}"

EXIT

CASE "B" ; cValue := "{||...}" ; EXIT CASE "C" ; cValue := xValue ; EXIT CASE "D" ; cValue := DtoS(xValue) ; EXIT CASE "L" ; cValue := IIf(xValue, ".T.",".F.") ; EXIT CASE "N" ; cValue := LTrim(Str(xValue)) ; EXIT CASE "O" ; cValue := xValue:className() ; EXIT DEFAULT

cValue := "NIL"

END

RETURN cValue

>

RETURN bBlock

= (assignment)

= (assignment)

Simple assignment operator (binary): assigns a value 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. The recommended assignment operator, however, is the inline assignment operator (:=) which allows for initializing a variable within a variable declaration statement. This is not possible with the simple assignment operator. In addition, the simple assignment operator is interpreted as comparison operator within expressions. This can lead to subtle programming errors since the meaning of the simple assignment operator changes with the context it is used in.

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: ++,--,:=,= (compound assignment) Category: Assignment operators,Operators

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example demonstrates the use of the assignment operator // and outlines the difference between simple and inline assignment.

PROCEDURE Main LOCAL nMonth

nMonth = 9 // simple assignment

? nMonth = 9 // result: .T.

IF (nMonth := 10) > 0 // inline assignment

? "October" // output: October ENDIF

IF (nMonth = 9) > 0 // runtime error

? "September" // (nMonth = 9) -> .F.

ENDIF RETURN

= (comparison)

= (comparison)

Equal operator (binary): compares two values for equality.

Syntax

<Expression1> = <Expression2>

Arguments

<Expression>

The values of <Expression1> and <Expression2> must have the same data type or can be NIL, and are compared.

Description

The "equal" operator compares two values of the same data type or NIL. It returns .T. (true) when the left operand has the same value as the right operand, otherwise the return value is .F. (false).

Only the simple data types Character, Data, Logic, Memo, Numeric and the value NIL can be compared. The complex data types Array, Code block, Hash and Object cannot be used with the

"equal" operator. This is only possible with the "exact equal" operator.

Comparison rules

Data type Comparison

Character The comparison is based on the ASCII value of the characters.

Date The comparison is based on the underlying date value.

Logical False (.F.) is not equal to true (.T.).

Memo Same as Character data type.

Numeric Comparison is based on the value of the numerics.

NIL NIL is equal to NIL and not equal to any other data type.

SET EXACT

For character comparisons, the "equal" operator takes the SET EXACT setting into account. With SET EXACT OFF, characters are compared up to the length of the right operand. With SET EXACT ON, characters are compared up to the length of the left operand and trailing blank spaces are ignored.

Info

See also: $,<,<=,<> != #,==,>,>=,SET EXACT Category: Comparison operators,Operators

LIB: xhb.lib

DLL: xhbdll.dll

Example

// The example shows results of the = operator.

PROCEDURE Main SET EXACT ON

? "ABC" = "ABC " // result: .T.

? "ABC " = "ABC" // result: .T.

? "" = "ABC" // result: .F.

= (comparison)

? "ABC" = "" // result: .F.

? "ABC" = "ABCDE" // result: .F.

? "ABCDE" = "ABC" // result: .F.

SET EXACT OFF

? "ABC" = "ABC " // result: .F.

? "ABC " = "ABC" // result: .T.

? "" = "ABC" // result: .F.

? "ABC" = "" // result: .T.

? "ABC" = "ABCDE" // result: .F.

? "ABCDE" = "ABC" // result: .T.

? CToD("12/28/2005") = CToD("12/31/2005") // result: .F.

? .T. = .F. // result: .F.

? NIL = NIL // result: .T.

? 2 = 1 // result: .F.

RETURN

= (compound assignment)

= (compound assignment)

Compound assignment (binary): inline operation with assignment.

Syntax

<Variable> += <cString> // inline string concatenation

<Variable> += <nNumber> // inline addition

<Variable> -= <cString> // inline string concatenation

<Variable> -= <nNumber> // inline subtraction

<Variable> -= <dDate> // inline subtraction

<Variable> *= <nNumber> // inline multiplication

<Variable> /= <nNumber> // inline division

<Variable> %= <nNumber> // inline modulus

<Variable> ^= <nNumber> // inline exponentiation

Arguments

<Variable>

<Variable> is the name of an arbitrary variable. It must be initialized with a value of a data type valid for the inline operation.

<cString>

<cString> is a character string used in the inline operation.

<nNumber>

<nNumber> is a numeric expression used in the inline operation.

<dDate>

<dDate> is a date value used in the inline operation.

Description

A compound operator takes the value o f the left operand and performs an inline operation with the value of the right operand, before it assigns the result to the left operand. Compound operators can therefore be used in expressions like the inline assignment operator.

The following table lists the operators and their equivalents:

In document xHarbour Language Reference Guide (Page 42-54)