How to get multiple listbox item positions


I’m programming dialogs to insert and remove items from an inventory. My inventory has shelves identified with letters and numbers, Ex. A6, U4, etc., with same items stored in multiple different shelves as there is a limited space in this inventory.

The remove inventory dialog looks like this image below:


In this example, there are 4 boxes of same items but with different serial numbers, listed in a listbox. If I want four items, I can select one box with more than four items and remove from it.

Until this part, it works fine. I call getSelectedItemPos and use this value to identify the box number where these items came from and register this information.

My problem start when I have to remove more than a single box contain. Let’s say that I want to remove 9 Items. I could select more than one box of items from the listbox and make a macro to remove all items from box with fewer items first then remove the remaining items from the second box.

I write down this segment of basic to get the position of the selected items, but it seems that getSelectedItemPos just get the position of the last selected item, not a vector of all the items selected positions.

When I select two itens from this listbox above, position 0 and position 2, the result of:

oListBox1 = oDialog.GetControl(“ListBox1”)
oSelectedValues = oListBox1.SelectedItems
oSelectedItemPos = oListBox1.getSelectedItemPos
for loopFor = 0 to uBound(oSelectedValues)
Next loopFor


Estante U | Prateleira 5 | Quantidade 44
Estante U | Prateleira 5 | Quantidade 4

Instead I need the position of both items, not just the last selected item:

Estante U | Prateleira 5 | Quantidade 44
Estante U | Prateleira 5 | Quantidade 4

Is there another function from listbox object that return the position of all selected items? How I can do that?

Thanks in advance.


As simple as that… :sweat_smile: Sometimes I got very confused about these basic function names.

These names are not “basic”, they are UNO API objects and methods, so have same names in Basic, Python, Java, C++, C# and so on. That’s why they are listed in the API documentation, not in Basic help.