Usina BRAdvPL Guide
Sign in
← CatalogFOUNDATION

AdvPL
operators

Symbols and words that perform calculations, comparisons, assignments and special operations in AdvPL expressions.

01

Mathematical

Perform numerical calculations.

** or ^

Exponentiation.

*

Multiplication.

/

Division.

%

Modulo: remainder of division.

+

Addition or positive sign.

-

Subtraction or negative sign.

EXAMPLE
Local nPotencia := 2 ^ 3     // 8
Local nProduto  := 6 * 4     // 24
Local nResto    := 10 % 3    // 1
02

Relational

Compare values and return a logical result.

<

Less than.

>

Greater than.

=

Simple equality; for strings, it may consider a partial match.

==

Exact equality, especially important for strings.

<=

Less than or equal to.

>=

Greater than or equal to.

<> or !=

Not equal.

#

Not equal, retained for compatibility; obsolete.

EXAMPLE
Local cCodigo := "ABC"

If cCodigo == "ABC"
    ConOut("Código exato")
EndIf
03

Logical

Combine or invert logical expressions.

.Not. or !

Logical negation.

.And.

Logical AND: all conditions must be true.

.Or.

Logical OR: at least one condition must be true.

EXAMPLE
Local lAtivo := .T.
Local nSaldo := 100

If lAtivo .And. nSaldo > 0
    ConOut("Disponível")
EndIf
04

Assignment

Store or update variable values.

:=

Assigns a value.

+=

Adds and assigns.

-=

Subtracts and assigns.

*=

Multiplies and assigns.

/=

Divides and assigns.

^= or **=

Raises to a power and assigns.

%=

Calculates modulo and assigns.

EXAMPLE
Local nTotal := 10

nTotal += 5   // 15
nTotal *= 2   // 30
nTotal %= 7   // 2
05

Increment and decrement

Change the value by one; position determines the value returned by the expression.

++x

Increments before returning the value.

x++

Returns the current value, then increments.

--x

Decrements before returning the value.

x--

Returns the current value, then decrements.

EXAMPLE
Local nX := 5
Local nAntes  := ++nX  // nX=6, nAntes=6
Local nDepois := nX++  // nDepois=6, nX=7
06

Strings

Concatenate or search character content.

x + y

Concatenates x and y.

x - y

Concatenates and moves trailing spaces from x to the end of the result.

x $ y

Returns true when x is contained in y.

EXAMPLE
Local cNome := "Usina" + ".BR"
Local lTem  := "AdvPL" $ "Guia AdvPL"

ConOut(cNome) // Usina.BR
ConOut(lTem)  // .T.
07

Special

Operate on code, structures, references, aliases and objects.

&cVariavel

Operador macro: avalia o conteúdo como expressão AdvPL.

| |

Delimita a lista de argumentos de um bloco de código.

( )

Chamada de função or agrupamento de expressão.

[ ]

Acesso a elemento de matriz.

{ }

Bloco de código or valores literais de matriz.

->

Acesso a campo por alias.

@

Passagem de parâmetro por referência.

;

Continuação or separação de instruções, conforme o contexto.

:

Envio de mensagem, acesso a método or membro de objeto.

EXAMPLE
Local aDados := {"A", "B"}
Local bExibe := {|cTexto| ConOut(cTexto)}
Local cCampo := "A1_NOME"

Eval(bExibe, aDados[1])
ConOut(SA1->&cCampo)
REFERENCES
  1. Programação em ADVPL. Microsiga, 10 ago. 2007, p. 6-7. Content reorganized with examples added.
  2. TOTVS. Operadores Comuns. TDN. Additional technical reference.
  3. TOTVS. Microsiga Protheus SDK. TDN — additional reference.