ListIndex()
Syntax
Index = ListIndex(linkedlist())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).
Parameter:
linkedlist() - The name of your linked list variable, created with the NewList command. You must specify 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, you have moved off the start or end of the list with PreviousElement() or NextElement() or you have used ResetList().
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)
Supported OS
All