gpt4 book ai didi

vb.net - InvalidCastException 未处理?

转载 作者:行者123 更新时间:2023-12-04 20:07:02 25 4
gpt4 key购买 nike

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com