Results 1 to 4 of 4

Thread: Need help understanding how to flag a number in relation to arrays. PLEASE

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    1

    Need help understanding how to flag a number in relation to arrays. PLEASE

    Let me clarify I don't want anyone to merely do it for me but I've hit a dead end. PLEASE help, my assignment for class is to use a random number generator to populate numbers for bet slips in a lottery type program. I am having trouble figuring out a way to mark a number as already in use so said number is not repeated. Any suggestions or know of any videos that can be helpful?
    Here is my program so far I highlighted where I am having trouble: https://docs.google.com/document/d/1...it?usp=sharing

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Need help understanding how to flag a number in relation to arrays. PLEASE

    Generally we advise that you post your code directly into the forum rather than linking to it. Most people won't check your link because they can't be sure what's on the far end of it. If you want your code to be formatted correctly you can mark it as code by using either the VB or # buttons.

    As for the question, probably the easiest strategy is to put all the possible items into a collection. Generate a random number to select an item from the collection and add it to your bet slip, at which point you remove the item from the collection. Then repeat.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,500

    Re: Need help understanding how to flag a number in relation to arrays. PLEASE

    Quote Originally Posted by hablahblahblah View Post
    I am having trouble figuring out a way to mark a number as already in use so said number is not repeated. Any suggestions or know of any videos that can be helpful?
    Here is my program so far I highlighted where I am having trouble:
    Try this:

    Add an invisible, unsorted ListBox.

    'Add' to the ListBox all the numbers you wish to use. A straight 1 to however many will do. (Doesn't have to start at 1 of course)

    While the ListBox count is > 0
    Generate a random number between 0 and ListBox.items.Count -1.

    Use the number in that ListBox Index as the selected number.
    Remove that index from the ListBox.
    (the count will now be one less and the remaining higher numbers will have all moved down one)

    This way you can only pull out unused numbers, and you don't have to wait for your RNG to find an unused number, which can take quite a while when you're down to the last few remaining numbers especially.

    Poppa.


    Oh... I see that's more or less what Funky Dexter's suggested.

    Pop.
    Last edited by Poppa Mintin; May 7th, 2016 at 11:06 AM. Reason: Sorry FD.
    Along with the sunshine there has to be a little rain sometime.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help understanding how to flag a number in relation to arrays. PLEASE

    Quote Originally Posted by Poppa Mintin View Post
    Try this:

    Add an invisible, unsorted ListBox.
    No. Never do that. That would be like using an invisible TextBox to store a String. The whole point of controls is to interact with the user. If there's no interaction then there should be no control. That rule might be broken for complex tasks that only a WebBrowser or RichTextBox can do but if all you want to do is store a list of items then just use an array or collection. If you use a ListBox, its Items property is a collection so why have the useless control attached?

    On another note, you might also create a randomised list in the first place and then just take the items one by one from the top of the list. You can follow the CodeBank link in my signature below and find a couple of threads on random items from lists.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width