Results 1 to 10 of 10

Thread: Quick question!

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    4

    Quick question!

    This is a program where you can enter 2 first letters of a state in the masked textbox, click the search button, and see the full name of the state displayed inside a regular textbox.
    I am having a little problem at the end getting txtOutput.Text to produce the name of the state selected. Here is what i have:
    Code:
    Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
            Dim first, last, middle As Integer
            Dim flag As Boolean = False
            first = 0
            last = lstStates.Items.Count - 1
            Dim letters As String = mtbFirstTwoLetters.Text.ToUpper
            While first <= last
                middle = CInt((first + last) / 2)
                Dim state As String =
                    CStr(lstStates.Items.Item(middle)).ToUpper
                If state.StartsWith(letters) Then
                    flag = True
                    Exit While
                Else
                    Dim st As String = state.Substring(0, 2)
                    If letters > st Then
                        first = middle + 1
                    Else
                        last = middle - 1
                    End If
                End If
            End While
            If flag Then
                txtOutput.Text = 
            Else
                txtOutput.Text = "The State Is Not Found"
            End If
        End Sub
    End Class
    Last edited by Hack; Nov 15th, 2012 at 11:26 AM. Reason: Added Code Tags

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