Results 1 to 3 of 3

Thread: [RESOLVED] VB6 Program; gets the mode of 10 numbers (HELP)

  1. #1

    Thread Starter
    New Member Smoochiegoo's Avatar
    Join Date
    Dec 2011
    Posts
    7

    Resolved [RESOLVED] VB6 Program; gets the mode of 10 numbers (HELP)

    The program accepts 10 numbers then it will arrange the numbers in ascending order then it will count the mode of the 10 numbers inputted. When we say mode, it is the number most frequently used. For example there are 10 numbers: 1,2,1,1,1,4,5,2,1,9 --> the most frequent number is 1 because its number of occurrence is 5, so the mode is 1.

    This is where the code of the getting the mode is inserted:

    for x = 0 to 9
    list1.additem num(x) --> This is where the 10 numbers are displayed in ascending order
    ~~~~CODES TO GET THE MODE/COUNT THE NUMBER OF OCCURRENCE OF EACH NUMBER~~~~
    next x
    ~~~~CODES TO DISPLAY THE MODE~~~~

    I don't know the codes for counting the number of occurrence of every number being entered. Please help me guys!

    THANK YOU IN ADVANCE

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 Program; gets the mode of 10 numbers (HELP)

    Looks like homework. We won't do your homework but will help point you in the right direction.

    - You can loop thru your listbox (after it is all filled out)
    - Maybe use the .ItemData property to store counts
    - Start from the 1st/current item and search for any matches from the next item til the end
    :: If its .ItemData property is non-negative, give it a count of 1 (keep reading below, it should make sense)
    -- if match found
    :: update the .ItemData property of the current item with the total count
    :: tag the found item's .ItemData with a negative value
    :: continue looping til end of list

    Now continue from the next list item. If the .ItemData value for that item is negative, you've already processed it, so skip it and go to the next item

    When all done, your listbox's .ItemData properties will either be a positive number or a negative number. Find the one with the largest positive number

    Edited:
    If the list is sorted, then it is much easier
    - keep track of which is the current number
    - loop til end of listbox
    - for each item that matches the current number, tally 1 more match.
    - when you hit an item that doesn't match the current number
    :: change the current number
    :: start a new tally for it
    :: when done with that number, if its tally is greater than the previously largest tally, cache it
    Last edited by LaVolpe; Jan 31st, 2012 at 11:07 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member Smoochiegoo's Avatar
    Join Date
    Dec 2011
    Posts
    7

    Re: VB6 Program; gets the mode of 10 numbers (HELP)

    Thanks for the help!

Tags for this Thread

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