This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Visual Basic: Comparing ListBoxes

 
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 ListBoxes.  ListBox1 is populated with 5 selected numbers from a CheckedListBox(LotteryBox) and ListBox2 is populated with random numbers 1-99.  I want to find a way to verify if the numbers in the two ListBoxes match.  For Example, if they matched one number.  It'll say "You've matched one number".  and so on.  I think I'm on the right path with:



But how do I differentiate between the five numbers selected in the LotteryBox?
 
Marshal
Posts: 70602
287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you make the selected items in each of the boxes into a collection and do anything like this on it? That will avoid your having to iterate the box 5×.

Duplicating discussion in our VB forum.
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Can you make the selected items in each of the boxes into a collection and do anything like this on it? That will avoid your having to iterate the box 5×.

Duplicating discussion in our VB forum.



I'm not real sure how to to that.  Here's the entire code:

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to create a collection, as suggested.  I received an error stating that Unable to cast object of type 'System.Int32' to type 'System.Windows.Forms.Control'


 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic