Load Listbox in order?

Hey all,
I have a list of people who collect “points” for doing various things, and wish to display the people in descending order of points. I want to load a listbox with the people loaded into the listbox in descending order already.

For example:

Name Points
John Smith 12
Mike Barnes 10
Harry Nelson 9
etc.

The people and the stored “points” are in arrays already. Is there a way to do this?

Two ways that I can see.

  1. Presort your arrays before loading into the list box - Points.SortWith(Names) - you’ll need to load from highest index to lowest.
  2. After loading your listbox set the sorted column & sort.

HTH

Check out SortWith http://documentation.xojo.com/index.php/Sortwith then load the listbox based on the sorted arrays

SortWith works great. What a pain this sort of thing was with VB6, and here its built right in. Nice.

Related to this, I have an odd issue I can’t figure out.

I have an array of people that starts out at 40, and can expand up to 43, based on the user’s actions (adding more people). The array index itself is set to (43). I want the display of the Listbox to adjust based on how many people are in the array.

The listbox loads the first time fine when I load the screen, but if I go back to the screen again, it adds a mysterious row and seems to duplicate names over and over again at the beginning, by 1 each time.

Below is an example of what I use to load the listbox (code is placed in Listbox Open event):

[code] 'Adds the user’s names to the array if they’re present, names are in oppgname, ydna is the storage for the user’s people they added, if any
if ydna(1)<>"" then oppgname(41)=ydna(1)
if ydna(2)<>"" then oppgname(42)=ydna(2)
if ydna(3)<>"" then oppgname(43)=ydna(3)
'Adds their respective points to the array, in case they aren’t 0, for sorting purposes
if ydna(1)<>"" then drivpoints(41)=ydpoints(1)
if ydna(2)<>"" then drivpoints(42)=ydpoints(2)
if ydna(3)<>"" then drivpoints(43)=ydpoints(3)

'Use this to sort the resulting array
drivpoints.SortWith(oppgname)

'Displaying in reverse order, because I want it displayed in descending order
for x = 43 DownTo 21
if oppgname(x)="" then Continue For
ListBox4.AddRow oppgname(x)
ListBox4.Cell(ListBox4.LastIndex,1)=Str(drivpoints(x))
next[/code]

Displayed in a separate Listbox (it was too large to fit into one) is the last 20 names, code is here:

for x = 20 DownTo 1 if oppgname(x)="" then Continue For ListBox5.AddRow oppgname(x) ListBox5.Cell(ListBox5.LastIndex,1)=Str(drivpoints(x)) next

Am I doing something wrong with the way i’m going about it?

add row will add a row to the listbox every time
do you ever remove all the rows so you can add them all back in ?

FYI a listbox IF you add more rows than can be visible will just add a scrollbar so you can scroll it
no need to split it into 2

Remove the rows? Doesn’t unloading the window the listbox is in unload the listbox itself as well?

Maybe I missed it but I didn’t see where you said you were doing that.
When you say " but if I go back to the screen again" you mean that window closed or just that you reactivate it ?

I close the window upon exiting the screen, I assumed that meant the listbox was closed and reset as well. I tried removing the rows from the listbox upon exiting, and I get Out of Range error, even though there are 40 rows.

Here is an example of the behavior now (decided to make it a straight 40 column listbox all the time), but it seems the SortWith thing has some sort of issue.

I have 40 names in an array, starting at 1 and going to 40 (I have nothing in the 0 spot).

When I load the listbox, it seems to sort it so that the 0 index has a name, but the 1 index is blank, so I end up with a blank name in the Listbox. Is there a way to make this type of sorted listbox display work with an array that starts at 1, and still display names in order of points?

I’d have to see the code your using to know
I’ve never encountered any issues with sort with or list boxes etc like you’re describing

Use listbox.deleteallrows to clear the listbox. What are the points for person(0)? If you put -1 in that position does the blank name move to the bottom of the list?