TList Next and Prev Item ?

BlitzMax Forums/BlitzMax Beginners Area/TList Next and Prev Item ?

Hi!!!

and sorry for my questions about TList but now i'm study how blitzmax manage it...

now the question...

i have a tList with n elements on it...

i can browse the list with "for .. eachin" OK

i can go to the first element with first() method... OK
i can go to the last element with last() Method... OK

but if i have an element that is in the middle of the list how can i get the next/previous one ?


thanks.

Quite frankly I'd be tempted to throw a RTFM here...
But here we go:
Get the TLink to your object by doing something like Local link:TLink = myList.FindLink(myObject)
Then use the link to travel back and forth the list, using link.NextLink() and link.PrevLink().

Just in case you genuinely don't have any idea where the info comes from, open the BlitzMax IDE, go to the Home tab, then Help>Modules>Litst.

Ok. Thanks Koriolis.

but you must admit that the "FM" is not so clean!
and "here" in the "beginners" area we are not all BlitzMax expert!

anyway thanks for your attention and answer.

This example shows how to navigate a list of items.
Complete with wrap-around:

Strict

' Initialise a TList called mylist
' This is used to hold a list of strings
Global mylist:TList=New TList

' add some items to mylist
mylist.AddLast "Apple"
mylist.AddLast "Banana"
mylist.AddLast "Pear"
mylist.AddLast "Blackberry"
mylist.AddLast "Peach"
mylist.AddLast "Mango"

' Initialise a TLink called link
' Set it to point to the first item in mylist
Global link:TLink=mylist.FirstLink()

' store the string from the first item into selected$
Global selected$=String(link.Value())

' open a small graphic window
AppTitle = "Lists - Next/Previous example"
Graphics 300,180,0,30|SOFTSYNC
SetClsColor $aa,$aa,$aa


Repeat
	
	' if user presses ESCAPE break out of the loop
	If KeyHit(KEY_ESCAPE) Exit
	
	' if user presses DOWN ARROW move to next item in list
	If KeyHit(KEY_DOWN) 
		link=link.NextLink()
		If link=Null link=mylist.FirstLink()
		selected$=String(link.Value())
	EndIf
	
	' if user presses UP ARROW move to previous item in list
	If KeyHit(KEY_UP)
		link=link.PrevLink()
		If link=Null link=mylist.LastLink()
		selected$=String(link.Value())
	EndIf
	
	' If DEL pressed remove selected item
	' Now point to the first item in the remaining list
	' If the list is empty exit from the loop
	If KeyHit(KEY_DELETE)
		mylist.Remove selected$
		link=mylist.FirstLink()
		If link=Null Exit
		selected$=String(link.Value())
	EndIf

	' if user presses RETURN key show item selected
	If KeyHit(KEY_RETURN)
		Notify "Your choice is "+selected$
	EndIf
	
	' show list and highlight the 'selected' item
	Cls
	SetColor $88,$44,$00
	DrawText "Cursors UP/DOWN to select item",10,10
	DrawText "RETURN to confirm selection",10,24
	Local y=55
	For Local l$=EachIn mylist
		SetColor $22,$22,$22
		If l$=selected$	SetColor $ff,$ff,$ff
		DrawText l$,40,y
		y:+16
	Next

	Flip
	FlushMem
Forever

End


but you must admit that the "FM" is not so clean!
Oh yeah, surely not :)
And I won't blame anyone for failing to find the information, not when the post is in the beginner's forum, like you say. Was just being sarcastically rude, kinda :p
Well maybe a bit more seriously rude, because some people really don't even try.

@jb (nice example! thanks)
@Koriolis thanks

thanks guys!

http://www.blitzbasic.com/Community/posts.php?topic=50285