是否可以使用IsNumeric()测试字符串并返回true,但是当您使用CInt()将相同的字符串转换为整数并将其分配给integer类型的变量时,它会给出类型不匹配错误?
我问因为我得到了一个类型不匹配错误,所以我在尝试强制转换之前使用IsNumeric()检查字符串是否为数字,但我仍然得到错误.
我正用这个撕掉我的头发.
这是有问题的代码.
iGlobalMaxAlternatives = CInt(strMaxAlternatives)是发生错误的地方.
Dim strMaxAlternatives As String
Dim iGlobalMaxAlternatives As Integer
iGlobalMaxAlternatives = 0
bSurchargeIncInFare = True
strMaxAlternatives = ReadStringKeyFromRegistry("Software\TL\Connection Strings\" & sConn & "\HH", "MaxAlt")
If IsNumeric(strMaxAlternatives) And strMaxAlternatives <> "" Then
iGlobalMaxAlternatives = CInt(strMaxAlternatives)
End If
Run Code Online (Sandbox Code Playgroud)