Gadget item index out of range.
BlitzMax Forums/BlitzMax Beginners Area/Gadget item index out of range.
| ||
I'm getting a "Gadget item index out of range" with this code when tries to remove an item from the listbox. This is a function to refresh the items in the list box and for this example i know that the number of items in the listbox is 2. The index # for the item starts at 0 so I added (a-1)since the index range is 0 to 1. Not 0 to 2 as the CountGadgetItems(FileListBox)would give me. Anyway,I'm doing something wrong here. [code] Function ListFiles() Local a:Int = CountGadgetItems(FileListBox) Print "a" If a > 0 Then 'If it's greater than zero then we know there is an item(s) in the listbox Local b:Int For b = 0 To (a - 1) RemoveGadgetItem(FileListBox, b) Next End If Local files:String[] files = LoadDir("c:\Map editor\Projects") For Local t:String = EachIn files AddGadgetItem FileListBox, t Next Print CountGadgetItems(FileListBox) End Function [code/] Last edited 2013 Last edited 2013 Last edited 2013 |
| ||
You can use the keyword Until, which is like doing To length-1 e.g. For b = 0 Until a Anyway, that's not your problem. Here's a question or two for you : You have a listbox with 2 items. You remove the first item in the Listbox (index zero). If you now look at the listbox, how many items does it have in it? What is the index of the remaining item? :-) |
| ||
I think I see what you are getting at.T he index for the ramaining item would be zero. |
| ||
Right. So when you come to remove the second item in your loop (index 1), it is no longer in that position. If you want to remove all items, you can also use ClearGadgetItems(). |
| ||
My goal was to remove all items. Should have known there was a function for it. Never the less a good excersice in removing items one at a time though. :) Thanks for the help. |