我正在登录我正在制作的项目,但令人讨厌的是,每当我点击“是”时,在我的消息框中,整个项目就会关闭,我不想发生这种情况。 / p>
以下是代码:
MsgBox("You have been successfully logged into our database!", MsgBoxStyle.Information, "Success!")
Else
MsgBox("Sorry, it looks like those values are incorrect, would you like to try again?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Whoops!")
If vbNo Then
Application.Exit()
Else
If vbYes Then
Me.Show()
End If
End If
End If
End Sub
End Class
正如您在vbYes代码行中看到的那样,我正在努力使消息框仅关闭,而不是实际项目,以便人们可以再次尝试。
答案 0 :(得分:1)
此:
MsgBox("Sorry, it looks like those values are incorrect, would you like to try again?", MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo, "Whoops!")
If vbNo Then
Application.Exit()
Else
If vbYes Then
Me.Show()
End If
End If
应该是这样的:
If MsgBox("Sorry, it looks like those values are incorrect, would you like to try again?",
MsgBoxStyle.Exclamation + MsgBoxStyle.YesNo,
"Whoops!") = vbNo Then
Application.Exit()
Else
Me.Show()
End If
我无法强烈建议您在此项目和IDE中转为Option Strict On
,以便{/ 1}}为将来创建的其他项目On
。您拥有的代码甚至无法使用Option Strict On
进行编译,这表明您正在尝试做一些您不应该做的事情。 vbNo
和vbYes
不是Boolean
值,因此不应该是If
语句的主题。