random - How to check if an item is already in a listbox in vb6 -


i'm working vb6 , want generate multiple randum numbers (the range detirmend user , number of generated answers) , send them listbox don't want duplicate generated numbers so.. want before sending generated number listbox check if exists in lisbox. if exists generate number if does't send the listbox

here have till max , min range chose numbers between answers number of generated numbers

    randomize = 1 answers step 1     generated = cint(int((max - min + 1) * rnd() + min))         n = 0 list1.listcount             if list1.list(n) <> gen             list1.additem (gen)             else             if list1.list = gen             'i don't know here              '(how go generate number)         next n next 

thank in advance keep in minde need keep things simple thank soo much

use boolean value keep result if same value generated in list.

private sub addrandomnumbers()     dim blniffound boolean     dim max integer     dim min integer     dim answers integer     max = 10     min = 1     answers = 5      randomize      while list1.listcount < answers          generated = cint(int((max - min + 1) * rnd() + min))         blniffound  = false          n = 0 list1.listcount             if list1.list(n) = generated                 blniffound = true                 exit             end if         next n          if blniffound = false list1.additem (generated)      loop  end sub 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -