Dim states As Collection = New Collection()
Sub Output(Value As String)
txtOutput.Text += Value + vbCrLf
End Sub
Sub ClearOutput(sender As Object, e As RoutedEventArgs) Handles btnClear.Click
txtOutput.Text = ""
txtInput.Text = ""
states.Clear()
End Sub
Sub btnAdd_Click(sender As Object, e As RoutedEventArgs) Handles btnAdd.Click
Dim input As String = txtInput.Text
states.Add(input)
Output("You added: " + input)
End Sub
Private Sub btnGet_Click(sender As Object, e As RoutedEventArgs) Handles btnGet.Click
Dim counter As Integer = 1
Dim stateID As String = txtInput.Text.ToString
If CStr(states.Count) = 0 Then
Output("Not found")
End If
For Each state As String In states
If states(counter).Contains(stateID) Then
If Not states(counter).Contains(",") Then
Output("Add a valid state entry e.g. California, CA")
Exit For
End If
Dim stateOnly = states(counter).Substring(0, state.IndexOf(","))
Output("You requested: " + states(counter))
Exit For
End If
counter = counter + 1
If counter > CStr(states.Count) Then
Output("Not found")
End If
Next
End Sub
Private Sub btnRemove_Click(sender As Object, e As RoutedEventArgs) Handles btnRemove.Click
Dim counter As Integer = 1
Dim stateID As String = txtInput.Text.ToString
Dim firstCount As Integer = CStr(states.Count)
If CStr(states.Count) = 0 Then
Output("Not found")
End If
For Each state As String In states
If states(counter).Contains(stateID) Then
If Not states(counter).Contains(",") Then
Output("Add a valid state entry e.g. California, CA")
Exit For
End If
states.Remove(counter)
txtOutput.Text = ""
Dim secondCount As Integer = CStr(states.Count)
If secondCount < firstCount And secondCount > 0 Then
counter = 0
Output(stateID + " removed; here's what's left:")
OutputStates()
Exit For
End If
If secondCount = 0 Then
Output("Nothing left.")
End If
End If
counter = counter + 1
If counter > CStr(states.Count) Then
Output("Not found")
End If
Next
End Sub
Sub btnShow_Click(sender As Object, e As RoutedEventArgs) Handles btnShow.Click
If CStr(states.Count) = 0 Then
Output("No entries yet")
End If
OutputStates()
End Sub
Sub OutputStates()
For Each state As String In states
Output(state)
Next
End Sub
키 값을 입력 양식을 사전에이 상태 모음 입력을 변환합니다,하지만 작품을 나던. Sub OutputStates()에 오류가 있습니다. 출력 (상태)은 사전이 사용될 때 더 이상 작동하지 않습니다. 나는 내가 stateID 및 stateName로, 입력 트림 필요가 있다고 생각하지만 난 당신의 하위에VB.net 어떻게 내가 코드 아래 시도
Dim states As Dictionary(Of String, String) _
= New Dictionary(Of String, String)
Sub Output(Value As String)
txtOutput.Text += Value + vbCrLf
End Sub
Sub ClearOutput(sender As Object, e As RoutedEventArgs) Handles btnClear.Click
txtOutput.Text = ""
txtInput.Text = ""
states.Clear()
End Sub
Sub btnAdd_Click(sender As Object, e As RoutedEventArgs) Handles btnAdd.Click
Dim input As String = txtInput.Text
Dim length As Integer = input.Length - 1
Dim stateID As String = input.Substring(0, 1)
Dim stateName As String = input.Substring(2, length)
states.Add(stateID, stateName)
Output("You added: " + input)
End Sub
Private Sub btnGet_Click(sender As Object, e As RoutedEventArgs) Handles btnGet.Click
Dim counter As Integer = 1
Dim stateID As String = txtInput.Text.ToString
If CStr(states.Count) = 0 Then
Output("Not found")
End If
For Each state In states
If states(counter).Contains(stateID) Then
If Not states(counter).Contains(",") Then
Output("Add a valid state entry e.g. California, CA")
Exit For
End If
Dim stateOnly = states(counter).Substring(0, states(counter).IndexOf(","))
Output("You requested: " + states(counter))
Exit For
End If
counter = counter + 1
If counter > CStr(states.Count) Then
Output("Not found")
End If
Next
End Sub
Private Sub btnRemove_Click(sender As Object, e As RoutedEventArgs) Handles btnRemove.Click
Dim counter As Integer = 1
Dim stateID As String = txtInput.Text.ToString
Dim firstCount As Integer = CStr(states.Count)
If CStr(states.Count) = 0 Then
Output("Not found")
End If
For Each state In states
If states(counter).Contains(stateID) Then
If Not states(counter).Contains(",") Then
Output("Add a valid state entry e.g. California, CA")
Exit For
End If
states.Remove(counter)
txtOutput.Text = ""
Dim secondCount As Integer = CStr(states.Count)
If secondCount < firstCount And secondCount > 0 Then
counter = 0
Output(stateID + " removed; here's what's left:")
OutputStates()
Exit For
End If
If secondCount = 0 Then
Output("Nothing left.")
End If
End If
counter = counter + 1
If counter > CStr(states.Count) Then
Output("Not found")
End If
Next
End Sub
Sub btnShow_Click(sender As Object, e As RoutedEventArgs) Handles btnShow.Click
If CStr(states.Count) = 0 Then
Output("No entries yet")
End If
OutputStates()
End Sub
Sub OutputStates()
For Each state In states
Output(states)
Next
End Sub
그것은 코드의 길이다. 증거에 넣고 관련 부분을 – theBugger
하위하여 btnAdd_Click 언급하시기 바랍니다 (개체로 보낸 사람, RoutedEventArgs으로 전자는)으로 btnAdd.Click 희미한 입력을 처리하는 문자열 = txtInput.Text states.Add (입력) 출력 ("당신은 추가 : "+ 입력) 최종 하위하여 btnAdd_Click (Object로서 송신자로서 RoutedEventArgs e)는 btnAdd.Click 정수 = input.Length로서 문자열 = txtInput.Text 희미한 길이 어둡게 입력 처리 – rkz
서브 - 문자열로 1 을 어둡게 stateID = input.Substring (0, 1) Dim stateName As String = input.Substring (2, length) states.Add (st ateID, stateName) 출력 ("사용자가 추가 함 :"+ 입력) End Sub – rkz