Was the InvalidCastException unhandled?

    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

      

This returns "Conversion from string" to print "Long" is invalid. I was wondering what the error is and how can I fix it? The other questions I looked at were mainly about variables that were assigning the wrong types, but I guess that this is not a problem It happens when all the variables are empty.

Thank!

+3


source to share


1 answer


What do you want to do. You want to check all of them: ""

. Then do the following:

If string.isNullOrEmpty(CustID) and _  
    string.isNullOrEmpty(FirstName) And string.isNullOrEmpty(SecondName) Then
        MsgBox("Please enter a term to search by")
    End If

      



Or you want to check if there is one of them ""

. Then do the following:

If string.isNullOrEmpty(CustID) orelse _  
    string.isNullOrEmpty(FirstName) orelse string.isNullOrEmpty(SecondName) Then
        MsgBox("Please enter a term to search by")
    End If

      

+2


source







All Articles