Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
VB.NET General Discussion
For Loop to search and determain how many their are.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="MattP, post: 127806, member: 16051"] Small example here. I'm not sure how you're having the user select numbers for their 'card'. In this case I just hardcoded 10 numbers in and split them on the ','. This would be bad UX and you'll want a more elegant way of letting the user select their numbers. The important part of the code is the For loop which iterates through each number the user selected and Array.Contains which checks the 'ballbox' to see if there is a match. [CODE] 'Create a random enumable range between 1 and 100 and take 5 Dim rnd As New Random Dim nums = Enumerable.Range(1, 100) _ .OrderBy(Function() rnd.Next) _ .Take(5) _ .ToArray() 'Hardcoded numbers the person selected for testing TextBox1.Text = "1,11,22,33,44,55,66,77,88,99" Dim selectedNumbers = TextBox1.Text.Split(",") Dim match As Integer = 0 'Loop to cycle through each number the user selected For Each num In selectedNumbers If nums.Contains(num) Then 'If the "ballbox" contains the number add 1 to your match counter match += 1 End If Next MessageBox.Show("Number of matches = " & match.ToString) End Sub[/CODE] I don't think there are any errors here but intellisense tanked on me and I can't test it until after the repair process is done. [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
VB.NET General Discussion
For Loop to search and determain how many their are.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom