CharacterText delimited by single or double quotes.
AdvPL GuideLocal <variável> := <valor> · ValType(<variável>)Learn how to create, name, initialize, and assign AdvPL variables and how their type follows the stored value.
A variable is a named reference to a value held in memory during execution. In traditional AdvPL, its type is dynamic: it is determined by the assigned value and may change during the variable lifetime. This differs from scope, which controls visibility and lifetime, and explicit As <type> typing, which documents and constrains the expected contract.
Local <variável> := <valor> · ValType(<variável>)CharacterText delimited by single or double quotes.
NumericInteger or decimal floating-point number.
DateA date created by Date(), CToD(), SToD(), or another date function.
LogicalTrue (.T.) or false (.F.).
ArrayA one-based indexed collection that may contain mixed types.
CodeBlockA set of expressions that can later be run with Eval().
ObjectAn instance of a class.
NILAbsence of a value; the usual initial state of an uninitialized declared variable.
User Function ExVariables()
Local cProduct := "Keyboard"
Local nQuantity := 2
Local nPrice := 150.50
Local lAvailable := .T.
Local dCreated := Date()
If lAvailable
MsgInfo(cProduct + " - total: " + ;
CValToChar(nQuantity * nPrice))
EndIf
ReturnEach variable receives an initial value that matches the intent communicated by its prefix.
User Function ExNil()
Local nPercentage
Local nResult
If ValType(nPercentage) == "U"
nPercentage := 10
EndIf
nResult := 250 * (1 + nPercentage / 100)
MsgInfo("Result: " + CValToChar(nResult))
ReturnValType() returns U while the variable has no value; initialization prevents NIL from entering the calculation.
User Function ExTipoDinamico()
Local xValor := "Pedido aberto"
ConOut("Tipo atual: " + ValType(xValor)) // C
xValor := 22
ConOut("Tipo atual: " + ValType(xValor)) // N
xValor := .T.
ConOut("Tipo atual: " + ValType(xValor)) // L
xValor := Date()
ConOut("Tipo atual: " + ValType(xValor)) // D
ReturnThe same variable holds different types. This flexibility should be intentional.
User Function ExConversao()
Local nQuantidade := 3
Local dHoje := Date()
Local lAtivo := .T.
ConOut("Quantidade: " + CValToChar(nQuantidade))
ConOut("Data: " + DToC(dHoje))
ConOut("Ativo: " + IIf(lAtivo, "sim", "não"))
ReturnEach value is converted to character before it is joined to text.
User Function ExErroDigitacao()
Local nQuantidade := 10
nQuantidad := 20 // nome incorreto: pode criar uma Private
MsgInfo("Quantidade: " + CValToChar(nQuantidade))
ReturnA missing letter may create another identifier rather than update nQuantity.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use