Re: Random listbox item selection



On Dec 21, 12:46 am, Charlie Brown <cbr...@xxxxxxxxxx> wrote:
On Dec 20, 4:58 pm, kimiraikkonen <kimiraikkone...@xxxxxxxxx> wrote:



On Dec 20, 7:43 pm, Kerry Moorman

<KerryMoor...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Family Tree Mike,

I think that should be:

listBox1.SelectedIndex = r.Next ( 0, listBox1.Items.Count)

because the range of values returned by Next includes the minvalue but
excludes the maxvalue.

Kerry Moorman

"Family Tree Mike" wrote:

"kimiraikkonen" wrote:

Hi,
How can i select next listbox item without obeying array order? How to
select an listbox item "randomly" inside the array?

Thanks.

dim r as new Random
listBox1.SelectedIndex = r.Next ( 0, listBox1.Items.Count - 1 )

Thanks "Kerry Moorman" and "Family Tree Mike",
It worked. The last question is: how may i determine if all the
listbox items were selected randomly? I mean, after all the listbox
items are selected, i want to get a msgbox that all the listbox items
are selected randomly, there's no item left unselected(in random
order).(just like an information about end of list)

Thanks!- Hide quoted text -

- Show quoted text -

try something like

if listbox.items.count = listbox.selecteditems.count then
'do something
end if

Hi, that doesn't work, only works with listbox's multiselect
(multiselect at the same time) function which is offtopic. I want to 2
thins if anyone can help:

For random selection procedure(as Kerry and Family Tree Mike helped);
1- I want an listbox item selected only for once, i don't want a
listbox item selected for twice or three (random order).
2-When all the items are selected in a random order, i want to get a
msgbox("all items were selected, there is no item left unselected in
random order").

Thanks!
.



Relevant Pages

  • Re: Fast way to clear Listbox selection
    ... When swithing from multiselect to singleselect, the listbox is rebuilt ... and the selection is cleared. ... Private Sub CommandButton1_Click ...
    (microsoft.public.excel.programming)
  • Re: Multiselect Listbox woes
    ... If your listbox is RowSource'd to an array or you AddItemthe selection ... items your multiselect will work fine. ... then tabs to another control or clicks ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Last Selection from MultiSelect Listbox
    ... What you can do is track the listbox selection in an array by modifying an array every time the listbox is changed. ... Dim idx As Integer, i As Integer ...
    (microsoft.public.excel.programming)
  • Re: Select range & copy
    ... I changed the range name of the ListBox stuff to mRefList ... "tvac" wrote: ... > Private Sub ListBox1_Click ... >> The first 2 columns have common data regardless of the selection. ...
    (microsoft.public.excel.programming)
  • Re: List of values
    ... I have to assume that the listbox is set to ... single-selection listbox. ... Private Sub ButtonOK_Click ... have shown is only the code to load the data into the listbox and display ...
    (microsoft.public.word.vba.general)

Loading