aMatrizVariable that stores the collection.
AdvPL GuideaMatriz := { <elemento1>, <elemento2>, ... } · aMatriz[nÍndice]Organize values in simple or multidimensional lists, access positions and change the structure dynamically.
Arrays are ordered collections of values. In AdvPL, the first element is at position 1, and one array may contain characters, numbers, dates, logical values, objects, other arrays and other types. Nested arrays can represent rows, columns and compound structures.
aMatriz := { <elemento1>, <elemento2>, ... } · aMatriz[nÍndice]aMatrizVariable that stores the collection.
nÍndiceElement position, starting at 1 and limited by the current array size.
elementoStored value; elements in the same array may have different types.
User Function ExArray()
Local aLetters := {"A", "B", "C"}
MsgInfo("Second element: " + aLetters[2])
MsgInfo("Count: " + CValToChar(Len(aLetters)))
ReturnIndex 2 returns B and Len() reports three elements.
User Function ExAppend()
Local aLetters := {"A", "B", "C"}
AAdd(aLetters, "D")
MsgInfo("Last element: " + aLetters[Len(aLetters)])
ReturnAAdd() appends D and Len() supplies the current last position.
#define PESSOA_NOME 1
#define PESSOA_IDADE 2
#define PESSOA_ATIVA 3
User Function ExPessoa()
Local aPessoa := {"Maria", 32, .T.}
If aPessoa[PESSOA_ATIVA]
ConOut(aPessoa[PESSOA_NOME] + " está ativa")
EndIf
ReturnConstants give semantic names to the positions holding name, age and status.
#define PESSOA_NOME 1
#define PESSOA_IDADE 2
User Function ExPessoas()
Local aPessoas := { ;
{"Pedro", 32}, ;
{"Maria", 22}, ;
{"Antônio", 42} }
Local nLinha
For nLinha := 1 To Len(aPessoas)
ConOut(aPessoas[nLinha, PESSOA_NOME] + ;
" - " + CValToChar(aPessoas[nLinha, PESSOA_IDADE]))
Next
ReturnEach inner array is a row. The loop iterates over people and accesses columns through constants.
User Function ExIndice(nIndice)
Local aCores := {"Azul", "Verde", "Vermelho"}
If nIndice >= 1 .And. nIndice <= Len(aCores)
MsgInfo(aCores[nIndice])
Else
MsgAlert("Posição inválida")
EndIf
ReturnThe condition prevents access outside the current array bounds.
© 2026 Usina.BR. Todos os direitos reservados. TOTVS, Protheus, Microsiga e seus respectivos logotipos são marcas de titularidade da TOTVS S.A. AdvPL é uma linguagem de programação desenvolvida pela TOTVS. O AdvPL Guia é um projeto independente, sem vínculo, representação, patrocínio ou afiliação com a TOTVS S.A., suas franquias ou representantes.