I am having trouble with this code and realizing that my flags are not work.
I am referring to a list box with US states inside.
See my code below and tell me what I am doing wrong. I can not output the state with first two letters.
A simple concept but I can not solve.
VB2010
Public Class frmStates
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim letter As String = mtbFirstTwo.Text.ToUpper
Dim Flag As Boolean = True
Dim state As String = ""
Dim first, mid, last As Integer
first = 0
last = CInt(lstStates.Items.Count) - 1
Do While (Not Flag) And (first <= last)
mid = CInt((first + last)) / 2
Select Case CStr(lstStates.Items(mid)).Substring(0, 2).ToUpper
Case letter
state = CStr(lstStates.Items(mid))
Flag = True
Case Is > letter
last = mid - 1
Case Is < letter
first = mid + 1
End Select
Loop
If Flag Then
txtOutput.Text = state & " begins with " & mtbFirstTwo.Text & "." 'can not get output
Else
txtOutput.Text = "No State begins with " & mtbFirstTwo.Text & "."
End If
End Sub