ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Queue, stack, list and array functions / Array functions
  • Adding an element into a WLanguage array
  • Adding an element to an advanced array property
  • Adding an element into a list
  • Adding an array into an array (concatenation)
  • Adding a list into a list (concatenation)
  • Adding the content of a structure to an array of structures without using a variable of the structure
  • Use conditions
  • 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 in last position:
  • of a one-dimensional WLanguage array.
  • of an advanced array property (array of gglCalendar events, array of Word Processing document, etc.).
  • from a WLanguage list.
This function can also be used to concatenate two arrays or two lists.
Remarks:
  • This function is equivalent to ArrayAdd.
  • WEBDEV - Browser codePHP This function can only be used with Array variables.
Example
MyArray is array of 2 strings
Add(MyArray, "WINDEV")
Add(MyArray, "WEBDEV")
Add(MyArray, "WINDEV and WEBDEV")
// Display the content of 3rd element (the first 2 elements are empty)
Trace(MyArray[3])  // Displays "WINDEV"
MyArray is array of 2 strings
MyArray[1] = "WINDEV"
MyArray[2] = "WEBDEV"
Add(MyArray, "WINDEV and WEBDEV")
// Display the content of 3rd element
Trace(MyArray[3]) // Displays "WINDEV and WEBDEV"
WINDEVWEBDEV - Server codeLinuxAndroidiPhone/iPadIOS WidgetMac CatalystJavaAjax
// Example to add an element into an XML file
NodeRSS is xmlNode,description="NEWS.rss.channel.item"
NodeRSS.title = DateToString(DateSys(), "DD/MM/YYYY") + " - " + ...
TimeToString(TimeSys(), "HH:MM") + ": " + sTitle
NodeRSS.description = sComment
NodeRSS.link = sHTTPLink
NodeRSS.enclosure:type = "image/jpeg"
NodeRSS.enclosure:length = 150
NodeRSS.enclosure:url = sURL_Image
 
Add(MyXMLDoc.rss.channel, NodeRSS)
XMLSave(MyXMLDoc, gsPathXMLFile)
Syntax

Adding an element to an array, to an advanced array property or to a list Hide the details

<Result> = Add(<WLanguage variable> [, <Value>])
<Result>: Integer
Index at which the specified element was added. If an error occurs, a fatal error is displayed.
<WLanguage variable>: Array or List
Name of variable to use. This variable can be:
  • An Array variable.
  • A List variable.
    WEBDEV - Browser codePHP This type of variable is not available.
<Value>: Type of array elements, optional
Value that will be added to the array or to the list. This parameter is mandatory for a list.
For an array, if this parameter is not specified, the array is enlarged with the default value of the type of the other array elements.

Concatenating arrays or lists Hide the details

<Result> = Add(<WLanguage variable> [, <Variable to concatenate>])
<Result>: Integer
Index at which the specified element was added. If an error occurs, a fatal error is displayed.
<WLanguage variable>: Array or List
Name of variable to use. This variable can be:
  • An Array variable.
  • A List variable.
    WEBDEV - Browser codePHP This type of variable is not available.
<Variable to concatenate>: Optional array or list
Name of variable that will be added after the existing elements. This variable can be:
  • An Array variable, to concatenate two arrays.
  • A List variable, to concatenate two lists.
    WEBDEV - Browser codePHP This type of variable is not available.
Remarks

Adding an element into a WLanguage array

When Add 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.
Remark: When declaring an array of N by M elements, this array contains N empty elements. For example, the array declared below contains 3 empty strings.
MyArray is array of 3 strings
When adding an element (Add), this element is automatically added after the elements already found in the array.
In our example, the added element will correspond to the 4th element.

Adding an element to an advanced array property

When Add is called:
  • the advanced variable must be created.
  • the advanced type must have an enumerator of modifiable collection type.
  • the advanced type is automatically enlarged to receive new elements.
  • the element is initialized with the value passed as parameter. If no value is passed as parameter, the element is initialized with the default value of the type of the array elements.

Adding an element into a list

When Add is called:
  • the list is automatically enlarged to receive the new element.
  • the element is converted (if necessary) into the type of the other list elements.
WEBDEV - Browser codePHP This feature is not available.

Adding an array into an array (concatenation)

When Add is called:
  • the array is automatically resized to include the new elements. The elements of <Name of variable to concatenate> are added at the end of <Variable name>.
  • the two arrays must have the same type.
  • the arrays must have the same dimension.
  • the array dimensions (other than the first dimension) must be identical.
    For example:
    Correct code:
    t1 is array of * by 2 int = [[1,2],[3,4]]
    t2 is array of * by 2 int = [[5,6],[7,8],[9,10]]
    Add(t1, t2)
    Invalid code:
    t1 is array of * by 3 int = [[1,2],[3,4]]
    t2 is array of * by 2 int = [[5,6],[7,8],[9,10]]
    Add(t1, t2)

Adding a list into a list (concatenation)

When Add is called:
  • the list is automatically enlarged to receive the new elements. The elements of <Name of variable to concatenate> are added at the end of <Variable name>.
  • both lists must be of the same type.
WEBDEV - Browser codePHP This feature is not available.

Adding the content of a structure to an array of structures without using a variable of the structure

If you are using an array of structures with few members, it may be easier to directly add a structure by using the [ ] operator (square brackets). For example, for the following structure:
// Structure to store a letter and its ASCII code
STKey is Structure
sKey is string
nAsciiCode is int
END
// Array of structures
arrKeys is array of STKey
In most cases, content is added by using a variable of a type declared in the structure:
// Temporary structure for the addition
stAKey is STKey
// Stores the letter A
stAKey.sKey = "A"
stAKey.nAsciiCode = Asc("A")
Add(arrKeys, stAKey)
With the [ ] operator, you get better legibility:
// Stores the letter A
Add(arrKeys, ["A", Asc("A")])

Use conditions

This function can be used with the structures. In this case, you must:
  1. Declare a variable (same type as the structure).
  2. Initialize each member.
  3. Pass the structure variable as parameter to Add.
This function cannot be used on:
  • non-created arrays.
  • fixed arrays.

Miscellaneous

Component: wd290vm.dll
Minimum version required
  • Version 14
This page is also available for…
Comments
Example result com 2 array
BuscaFoto(ID_ORIGEM)

ID_Unico_Foto is 8-bytes int
FotoLocalizada is Buffer

IF HExecuteQuery(QRY_Fotos,CONNX,hQueryDefault,ID_ORIGEM) = True THEN

FOR EACH QRY_Fotos

ID_Unico_Foto = QRY_Fotos.T002_ARQUIVOSID
FotoLocalizada = QRY_Fotos.T002_ARQUIVO

END

END

arresultado is array of Variant ///IMPORTANTE

Add(arresultado,ID_Unico_Foto)
Add(arresultado,FotoLocalizada)

RESULT arresultado

//------- USE:

ArrResult is array of variant = BuscaFoto(1)
EDT_CodigoImagem = ArrResult[1]
IMG_Foto = ArrResult[2]
BOLLER
17 Apr. 2019

Last update: 07/03/2023

Send a report | Local help