Dim CustID As String = txtSrchCustID.Text
Dim FirstName As String = txtNewCustFName.Text
Dim SecondName As String = txtNewCustSName.Text
If CustID And FirstName And SecondName = "" Then
MsgBox("Please enter a term to search by")
EndIf
这将返回“从字符串“”到类型“Long”的转换无效。”我想知道错误是什么以及如何修复它?我看过的其他问题主要与分配了错误类型的变量有关,但我认为这不是问题所在。它发生在所有变量都为空时。
谢谢!
最佳答案
你想做什么。您要检查所有 是否都是""
。然后这样做:
If string.isNullOrEmpty(CustID) and _
string.isNullOrEmpty(FirstName) And string.isNullOrEmpty(SecondName) Then
MsgBox("Please enter a term to search by")
End If
或者你想检查它们中的一个是否是“”
。然后这样做:
If string.isNullOrEmpty(CustID) orelse _
string.isNullOrEmpty(FirstName) orelse string.isNullOrEmpty(SecondName) Then
MsgBox("Please enter a term to search by")
End If
关于vb.net - InvalidCastException 未处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10011987/