AddElement()
Syntax
Result = AddElement(List())Description
Adds a new empty element after the current element or as the first item in the list if there are no elements in it. This new element becomes the current element of the list.
Parameters
List() The name of your list variable, created with the NewList function. You must include the brackets after the list name.
Return value
Returns non-zero if the new element was created and zero otherwise. The value returned is a pointer to the new element data.
Example
; The simplest way to use AddElement NewList simple.w() AddElement(simple()) ; Creates the first new element in the list simple() = 23 AddElement(simple()) ; Current position is the first element, so we add one to the second position simple() = 45 ; This shows how to use the return-value of AddElement NewList advanced.l() If AddElement(advanced()) <> 0 advanced() = 12345 Else MessageRequester("Error!", "Unable to allocate memory for new element", #PB_MessageRequester_OK) EndIf ; A small structure to demonstrate the use of the pointer to the new element Structure Programmer Name.s Strength.b EndStructure NewList Programmers.Programmer() ; The list for storing the elements *Element.Programmer = AddElement(Programmers()) If *Element<>0 *Element\Name = "Dave" *Element\Strength = 3 ; Wow, super-strong geek! ;) Else MessageRequester("Error!", "Unable to allocate memory for new element", #PB_MessageRequester_OK) EndIf
See Also
InsertElement(), DeleteElement(), ClearList()
Supported OS
All