|
-
Jan 7th, 2009, 02:47 PM
#1
Thread Starter
New Member
[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
-
Jan 7th, 2009, 03:16 PM
#2
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.
-
Jan 7th, 2009, 03:33 PM
#3
Thread Starter
New Member
-
Jan 7th, 2009, 04:16 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|