-1

我正在使用答案框进行测验并检查我的答案框。

我输入代码,然后当我输入答案时,它说“再试一次错误”,当我在框中什么都不写时,它说“正确,做得好”。

我输入的代码如下:

Private Sub CommandButton1_Click()
If TextBox1.Value = motherboard Then
    MsgBox "Correct. Well done!"
    SlideShowWindows(1).View.Next
Else
    MsgBox "Wrong answer. Try again."
End If
4

1 回答 1

0
Private Sub CommandButton1_Click()
If TextBox1.Value = "motherboard" Then
    MsgBox "Correct. Well done!"
    SlideShowWindows(1).View.Next
Else
    MsgBox "Wrong answer. Try again."
End If

如果没有在另一个位置定义主板,我假设您希望文字答案是文本“主板”所以您需要在单词周围添加引号。

它在没有答案时接受您的答案的原因是,当您添加一个未定义的变量时,它的默认值为 none。因此,当您不输入任何内容时,它与一个也不等于任何内容的变量匹配。通过添加引号,它可以准确地查找该单词。

您可能还想向传入的文本添加某种过滤器,以使其更有可能获得正确的答案,该答案可能有额外的空间来排除大写字母。

Private Sub CommandButton1_Click()
If Trim(LCase(TextBox1.Value)) = "motherboard" Then
    MsgBox "Correct. Well done!"
    SlideShowWindows(1).View.Next
Else
    MsgBox "Wrong answer. Try again."
End If

添加 LCase 命令将使所有输入的文本小写。添加修剪命令将删除单词前后的所有空格。

于 2013-10-09T16:50:13.780 回答