LastElement()

Syntax

Result = LastElement(List())
Description
Change the current list element to the last list element.

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 the address of the data in the last list element if successful and zero if there if there are no elements in the list.

Example

  ; An example of simple usage
  NewList Numbers.w()

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  LastElement(Numbers())
  MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)


  ; An example which uses the return-value
  NewList Numbers.w()

  If LastElement(Numbers()) <> 0
    MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  If LastElement(Numbers()) <> 0
    MessageRequester("Information", "Last element value is "+Str(Numbers()), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf


  ; An example which is only for advanced users
  NewList Numbers.w()

  AddElement(Numbers())
  Numbers() = 5
  AddElement(Numbers())
  Numbers() = 8

  *Element.Word = LastElement(Numbers())
  If *Element
    MessageRequester("Information", "Last element value is "+Str(*Element\w), #PB_MessageRequester_OK)
  Else
    MessageRequester("Information", "List is empty", #PB_MessageRequester_OK)
  EndIf

See Also

FirstElement(), PreviousElement(), NextElement(), SelectElement(), ListIndex()

Supported OS

All

<- InsertElement() - List Index - ListIndex() ->