-
Mar 29th, 2016, 12:51 PM
#1
Thread Starter
New Member
Number sequence in VB.Net
I have a 30 buttons each label 1-10 three times, so i have three 1's, three 2's etc.
I have 4 text boxes, when i hit any 4 buttons then it will fill the 4 boxes.
I need to return a value of true if the text boxes contain 3 numbers that can be in order.
So if the number was 7498 then that would be true - 789
or 9243 would be true as 234.
I tried to compare the boxes and then add a count, if x = 3 then true but I ran into trouble as the boxes can have the same numbers - 2223.
Any ideas as I am completely lost now - been staring at it so long it doesn't look like it is in English any more.
-
Mar 29th, 2016, 01:14 PM
#2
Re: Number sequence in VB.Net
Your logic doesn't make sense to me because would mean that your term of sequential numbers would allow a different number breaking up the sequence as is the case with 7689(your sequence: 789 but a true sequence would be: 89).
Anyways, with that aside take a look at this function and see if it works for you:
Code:
Private Function SequentialNumbers(ByVal input As String) As Boolean
Dim numbers() As Int32 = Array.ConvertAll(input.ToCharArray(), Function(c) Convert.ToInt32(c))
For index As Int32 = 0 To numbers.Length - 2
For nestedIndex As Int32 = index + 1 To numbers.Length - 1
If numbers(index) = numbers(nestedIndex) - 1 Then
Return True
End If
Next
Next
Return False
End Function
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|