[2008] Randomly check items in a CheckedListBox
Hi, I'm new to VB and I have a few problems.
Ok so what I want is to select random items from a CheckedListBox and then print them to a sheet of paper. I also want to define how many random items are checked via a TextBox. Let's say I have 50 items in the CheckedListBox and I want to randomly select only 10 (more or less - user defined via the TextBox) of them and print them to a sheet of paper.
Thanks for the help in advance. :P
Re: [2008] Randomly check items in a CheckedListBox
Once the user enters the number in a textbox, convert to int and perform a loop that many times (say, x).
In each iteration, call the Random class' Next() method, but limit it to the number of items in the checkboxlist.
So you can have something like
randomObject.Next(0, CheckBoxList1.Items.Count -1)
And whatever you get back from there is the index of the item you should check.
However, to add to this a bit, you will also need to ensure that the number returned hasn't been returned in a previous iteration, so you may want to start by generating the 10 random numbers first and storing them in a list.
Re: [2008] Randomly check items in a CheckedListBox
I'm a little embarrassed to say it but... I really am new to VB :D and I don't have almost any idea how to start "codding". If you are not too busy could you uhm... be able to write the code for me, with the print function :blush: I'd be really grateful. :blush:
P.S: I'm so embarrassed right now. :S :blush:
Re: [2008] Randomly check items in a CheckedListBox
There's no need to be embarrassed. I won't write the code for you because you're a beginner and I feel that you should learn this stuff.
Take it step by step. First, read the value from the textbox.
Then, set up a for-next loop. Try this out first and if you get stuck, post again asking about it.