ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Queue, stack, list and array functions / Array functions
  • Adding an element
  • Miscellaneous
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Adds an element to a one-dimensional WLanguage array taking into account:
  • the sort criteria defined by ArraySort
  • the comparison operator described in the class, if the elements of the array are class instances.
Remark: This function can only be used on WLanguage arrays.
Example
MyArray is array of 2 strings
MyArray[1] = "WINDEV"
MyArray[2] = "WEBDEV"
ArraySort(MyArray, asAscending)
ArrayAddSorted(MyArray, "WEBDEV and WINDEV")
// Display the content of elements
Trace(MyArray[1]) // Displays "WEBDEV"
Trace(MyArray[2]) // Displays "WEBDEV and WINDEV"
Trace(MyArray[3]) // Displays "WINDEV"
Syntax
<Result> = ArrayAddSorted(<WLanguage array> , <Element value>)
<Result>: Integer
  • Index at which the specified element was added,
  • -1 if the element could not be added.
A WLanguage error occurs if:
  • no sort criteria have been defined (ArraySort function or comparison operator in the class).
  • the array did not meet the sort criteria before the addition.
<WLanguage array>: Array
Name of the Array variable to use. This array must be a one-dimensional array.
<Element value>: Type of array elements
Element that must be added to the specified array.
Remarks

Adding an element

When ArrayAddSorted is called:
  • the array is automatically enlarged to receive the new element.
  • the element is converted (if necessary) into the type of the other array elements.
  • the element is placed in the array according to the sort.

Miscellaneous

This function cannot be used on:
  • non-created arrays,
  • fixed arrays.
Business / UI classification: Neutral code
Component: wd290vm.dll
Minimum version required
  • Version 12
This page is also available for…
Comments
exemplo arraysort e ArrayAddSorted
https://windevdesenvolvimento.blogspot.com/2021/04/dicas-3314-windev-webdev-mobile.html
https://youtu.be/PQZn6DuyNoM
//exemplo arraysort e ArrayAddSorted
// vamos criar um Array com 10 itens
arrMeu_array is array of 10 strings
// Vamos criar um contador inteiro comecando com zero
contador is int=0
// Vamor fazer um Loop
LOOP
// Vamos Somar o Contador um a um
contador+=1
// Vamos Adicionar no array a Palavra numero mais o contador
arrMeu_array[contador]="Numero:"+NumToString(contador,"02d")
// Se o contador for igual a 10, vamos encerrar o loop
IF contador=10 THEN
// sair do Loop
BREAK
END
END
// Vamos fazer a Classificacao do array em ordem alfabetica
ArraySort(arrMeu_array, asAscending)
// Vamos adicionar ao nosso array ja na ordem acima a palavra Numero 11
ArrayAddSorted(arrMeu_array, "Numero:11 ")
// Vamos Limpar a TAbela
TABLE_clientes.DeleteAll()
// vamos varrer todo o conteudo do array
FOR EACH ELEMENT sNome OF arrMeu_array
// vamos adic
amarildo
26 Apr. 2021

Last update: 05/26/2022

Send a report | Local help