Some List Index functions for you...

BlitzMax Forums/BlitzMax Programming/Some List Index functions for you...

Grey Alien(Posted 2006) [#1]
Someone might find these useful or know of a better way to do it. I find them useful...

' -----------------------------------------------------------------------------
' ccListIndex
' -----------------------------------------------------------------------------
Function ccListIndex%(list:TList, value:Object Var)
	'Loop through a list and return the index of the matching object.
	Local index = 0
	For Local o:Object = EachIn list
		If o = value Then Return index
		index:+1
	Next
	'No match
	Return -1
End Function

' -----------------------------------------------------------------------------
' ccListStringIndex
' -----------------------------------------------------------------------------
Function ccListStringIndex%(list:TList, s$)
	'Loop through a string list and return the index of the matching string.
	Local index = 0
	For Local o:Object = EachIn list
		If String(o) = s Then Return index
		index:+1
	Next
	'No match
	Return -1
End Function