Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidCastException was 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 type 'Long' is not valid." I was wondering what the error is and how it's possible to fix it? The other questions that I've looked at were mostly to do with variables assigned incorrect types, but I think that isn't the issue. It occurs when all of the variables are empty.

Thanks!

like image 591
Paul Avatar asked Mar 22 '26 20:03

Paul


1 Answers

What do you want to do. Do you want to check of all of them are "". Then do this:

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

Or do you want to check if one of them are "". Then do this:

If string.isNullOrEmpty(CustID) orelse _  
    string.isNullOrEmpty(FirstName) orelse string.isNullOrEmpty(SecondName) Then
        MsgBox("Please enter a term to search by")
    End If
like image 120
Arion Avatar answered Mar 25 '26 20:03

Arion