Results 1 to 2 of 2

Thread: Number sequence in VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2015
    Posts
    10

    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.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,698

    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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

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