List problem

BlitzMax Forums/BlitzMax Beginners Area/List problem

jankupila(Posted 2010) [#1]
merkit:TList=CreateList()
nimet:TList=CreateList()

Local B:String
Local C:String

ListAddLast merkit,"Fe"
ListAddLast merkit,"S"
ListAddLast merkit,"P"
ListAddLast merkit,"Si"

ListAddLast nimet,"Rauta"
ListAddLast nimet,"Rikki"
ListAddLast nimet,"Typpi"
ListAddLast nimet,"Pii"


For a$=EachIn merkit
	Print a$
Next
For a$=EachIn nimet
	Print a$
Next

'How do I easily take third object to "B" from list "merkit"
'and third object from list "nimet" to "C"?



Last edited 2010


GfK(Posted 2010) [#2]
B = String(merkit.ValueAtIndex(3))


C = String(nimet.ValueAtIndex(3))



jankupila(Posted 2010) [#3]
Thanks a lot! It was easier than I thought.


GfK(Posted 2010) [#4]
No probs. Just so you know, ValueAtIndex iterates through the entire list until it gets to the right index. Normally not a problem but the larger the list, the slower it gets. If you're doing this with lists containing hundreds/thousands of objects then you might be better off using an array.