vb.net - InvalidCastException 未处理?

标签 vb.net exception casting

    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/

相关文章:

javascript - 为什么我的 onchange asp.net 组合框没有被调用?

vb.net - LINQ 泛型 SUM - VB.NET

c# - 获取应用程序的 NotifyIcon 矩形?

java - @After 的 AOP 切入点

c++ - C++ 示例的错误

vb.net - 如何使用 .net vb 在 paypal IPN 处理程序上获取运输信息(地址、城市等)

c++ - std::exception.what() 在 clang 和 gcc 上返回意外值,但在 VS11 上不返回

java - 为什么我不能在 try catch 语句中调用的方法中抛出异常(已检查)?

当 list 添加为资源时,Delphi 5 导致 EAccessViolation

c++ - 私有(private)继承和隐式转换