gpt4 book ai didi

vba - 为什么 "If Value is Nothing"抛出 "Object Required (Error 424)"

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

以下代码抛出 Object Required (Error 424)在 if 语句比较 Nothing独立于给定的值。为什么?

Public Function SqlizeCellValue(ByVal Value As Variant) As Variant
If Value Is Nothing Then
SqlizeCellValue = Nothing
ElseIf Value = Null Then
SqlizeCellValue = Null
ElseIf Value = "" Then
SqlizeCellValue = Null
ElseIf Value = "0" Then
SqlizeCellValue = Null
ElseIf Value = "---" Then
SqlizeCellValue = Null
ElseIf LCase(Value) = "n.c." Then
SqlizeCellValue = Null
Else
SqlizeCellValue = Value
End If
End Function
Public Sub TestSqlizeCellValue()
Debug.Assert SqlizeCellValue("") Is Null
Debug.Assert SqlizeCellValue("0") Is Null
Debug.Assert SqlizeCellValue("---") Is Null
Debug.Assert SqlizeCellValue(Nothing) Is Nothing
Debug.Assert SqlizeCellValue(Null) Is Null
End Sub

最佳答案

因为 Value在您的函数定义中设置为类型 Variant只有一个 Object可以 SetNothing

关于vba - 为什么 "If Value is Nothing"抛出 "Object Required (Error 424)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38228269/

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