Vba 在Visual Basic 2012中使用带InStr的脏话过滤器

Vba 在Visual Basic 2012中使用带InStr的脏话过滤器,vba,Vba,我想将IF参数与字符串数组进行比较。用户将尝试将teamname放入文本框中,如果用户在该文本框中的任何位置使用脏话,它将显示错误消息并清除该文本框。如果用户尚未宣誓,则将注册团队名称并继续执行程序(如第二条If语句所示)。我已经试着让这个代码工作了一个星期,但无法让它工作 Private Sub SelectionButtonEnter_Click(sender As Object, e As EventArgs) Handles SelectionButtonEnter.Click

我想将IF参数与字符串数组进行比较。用户将尝试将teamname放入文本框中,如果用户在该文本框中的任何位置使用脏话,它将显示错误消息并清除该文本框。如果用户尚未宣誓,则将注册团队名称并继续执行程序(如第二条If语句所示)。我已经试着让这个代码工作了一个星期,但无法让它工作

Private Sub SelectionButtonEnter_Click(sender As Object, e As EventArgs) Handles SelectionButtonEnter.Click
    Dim HasSworn As Boolean = False
    Dim swears() As String = {"Fuck", "fuck", "Shit", "shit", "Shite", "shite", "Dick", "dick", "Pussy", "pussy", "Piss", "piss", "Vagina", "vagina", "Faggot", "faggot"} 'Declare potential swear words the kids can use
    For Each swear As String In swears
        If InStr(SelectionTextBoxTeamName.Text, swear) > 0 Then
            SelectionTextBoxTeamName.Clear() 'Clear the textbox
            MessageBox.Show("Remember ... You can be disqualified, raise your hand and Blair will set up the program for you again") 'Let the user know they have entered a swear word and ask them to select another team name
        End If
        If Not InStr(SelectionTextBoxTeamName.Text, swear) > 0 Then
            Timer1.Enabled = True 'Enable timer 1 for the learn box
            Timer3ForSelection.Enabled = True 'Enable this timer to show the learn button
            TeamName = SelectionTextBoxTeamName.Text() 'Once this button has been pressed, store the content of that textbox in a the TeamName string 
            SelectionLabelTeamName.Text = "Welcome " & SelectionTextBoxTeamName.Text & " Please click 'Learn' in the box below to begin" 'Display the contents of the string along with other text here
            SelectionLabelTeamNameTL.Text() = "Team Name: " & TeamName 'Display the contents of the string along with other text here
            SelectionTextBoxTeamName.BackColor = Color.Green 'Have the back color of the box set to green
            SelectionTextBoxTeamName.Enabled = False 'Do not allow the user/users enter another team name
        End If
    Next 'A next must be declared in a for each statement
End Sub

提前谢谢。

我想我不会那样做;如果用户键入f**kyou,您的代码将无法捕获它。这个怎么样

在代码中:

If ContainsBannedWord(SelectionTextBoxTeamName.Text) Then
   Msgbox "Hold out your hand, bad person. SlapSlapSlap"
Else
   Msgbox "Good boy!"
End if

Function ContainsBannedWord(sInput As String) As Boolean

    Dim aBannedWords(1 To 5) As String
    Dim x As Long

    ' Make all the banned words capitalized
    aBannedWords(1) = "BANNED1"
    aBannedWords(2) = "BANNED2"
    aBannedWords(3) = "BANNED3"
    aBannedWords(4) = "BANNED4"
    aBannedWords(5) = "BANNED5"

    For x = LBound(aBannedWords) To UBound(aBannedWords)
        If InStr(UCase(sInput), aBannedWords(x)) > 0 Then
            ContainsBannedWord = True
            Exit Function
        End If
    Next

    ContainsBannedWord = False

End Function