为什么这段代码失败? [英] why this code fails?
本文介绍了为什么这段代码失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Private Sub Button2_Click (sender As System.Object, e As System.EventArgs) Handles button2.click
As Integer Dim question
Question = Val (InputBox ("Capital of Turkey?", "Question 2", 30, 40))
If ısnothing (question = ("ankara")) Than
MsgBox ("Wrong answer")
Else: question = ("ankara")
MsgBox ("Correct Answer")
End If
End Sub
推荐答案
<错误用法< a href =https://msdn.microsoft.com/en-us/library/5adx7fxz%28v=vs.90%29.aspx> IsNothing功能 [ ^ ]!IsNothing
返回一个布尔值,指示表达式是否没有为其分配对象。
试试这个:
Bad usage of IsNothing function[^]!IsNothing
returns a boolean value indicating whether an expression has no object assigned to it.
Try this:
Dim question As String
question = InputBox("Capital of Turkey?", "Question 2")
MsgBox "The answer is " & IIf(question = "Ankara", "", "not ") & "correct!"
注意:为了确保一个字符串与另一个字符串相等,您需要知道比较取决于许多因素,例如:站点代码,大/小写字母等。
我建议读这个:
Visual Basic中的比较运算符 [ ^ ]
StrComp函数(Visual Basic) [ ^ ]
这篇关于为什么这段代码失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文