ListIndex()

Syntax

Index = ListIndex(List())
Description
Find out the position of the current element in the list, considering that the first element is at the position 0. This function is very fast, and can be used a lot without performance issue (it doesn't iterate the list but uses a cached value).

Parameters

List() The name of your list variable, created with the NewList function. You must include the brackets after the list name.

Return value

A number containing the position of the current element within the list. The first element is at position 0, the next at 1 and so on. A value of -1 means there is no current element (either the list is empty or ResetList() has been used).

Example

  NewList fruit.s()

  AddElement(fruit()) : fruit() = "oranges"
  AddElement(fruit()) : fruit() = "bananas"
  AddElement(fruit()) : fruit() = "apples"
  AddElement(fruit()) : fruit() = "pears"

  FirstElement(fruit())
  MessageRequester("Fruit: "+fruit(), "Now at position "+Str(ListIndex(fruit())),  #PB_MessageRequester_OK)

  NextElement(fruit())
  MessageRequester("Fruit: "+fruit(), "Now at position "+Str(ListIndex(fruit())),  #PB_MessageRequester_OK)

  NextElement(fruit())
  MessageRequester("Fruit: "+fruit(), "Now at position "+Str(ListIndex(fruit())),  #PB_MessageRequester_OK)

  NextElement(fruit())
  MessageRequester("Fruit: "+fruit(), "Now at position "+Str(ListIndex(fruit())),  #PB_MessageRequester_OK)

See Also

SelectElement(), ListSize()

Supported OS

All

<- LastElement() - List Index - ListSize() ->