我需要检查输入是否为空/空。如何检查输入是否为空/空
If input <= 100 And input > 0 And Not input = "" Then
subjectsInt.Add(subjects(i), input)
check = True
End If
我知道在该代码我检查它作为字符串,但我已经做了Not input = Nothing
和Not input = 0
,我得到一个错误:
Run-time exception (line -1): Conversion from string "" to type 'Integer' is not valid.
Stack Trace:
[System.FormatException: Input string was not in a correct format.]
[System.InvalidCastException: Conversion from string "" to type 'Integer' is not valid.]
有什么建议?
编辑
这里是你想看看在情况下,代码:https://dotnetfiddle.net/0QvoAo
它必须是'AndAlso',你必须先测试它。所以'如果没有输入=“”AndAlso(输入> 0并且输入<= 100)然后'。并且还提供* short-circuit *表达式的评估。总是一个好主意,使用Option Strict On编程一段时间后,尼采会输入“asdf”来查看失败,并使用TryParse()。 –
@HansPassant检查编辑部分:https://dotnetfiddle.net/0QvoAo – NietzscheProgrammer
为什么我收到downvote?你们只是滥用这种功能。我的问题出了什么问题? – NietzscheProgrammer