0

我需要创建一个可以搜索用户想要搜索的字母的程序。用户将在文本框中写下一些内容,当他/她按下搜索时,会出现一个输入框,要求他在输入框上写一个字母。然后程序会告诉您该字母出现在文本框中的时间很多。这是我到目前为止所拥有的:

Public Class Form1

    Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        TxtboxInput.Clear()
    End Sub

    Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click
        Me.Close()
    End Sub

    Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
        Dim intStartIndex As Integer
        Dim intFoundIndex As Integer
        Dim counter = 0
        Dim hitcounter = 0
        Dim blnFlag = True
        Try

            InputBox(" Enter Letters", "Input Needed")
        Catch
        End Try
    End Sub
End Class
4

1 回答 1

0

我不确定您到底要做什么,但是如果您将其限制为单个字符,那么这样的事情应该可以工作。

Private Sub BtnSearch_Click(sender As System.Object, e As System.EventArgs) Handles BtnSearch.Click
    Dim counter = 0
    Try
        Dim search As String = InputBox(" Enter Letters", "Input Needed")
        For Each c As Char In TxtboxInput.Text
            If c.ToString = search Then
                counter += 1
            End If
        Next
    Catch
    End Try
End Sub
于 2013-04-02T03:23:12.047 回答