3
以下代碼在if語句處拋出Object Required (Error 424)
,與Nothing
比較,與給定的值無關。爲什麼?爲什麼「If Value is Nothing」拋出「Object Required(Error 424)」
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'可以設置爲' Nothing'。 – Dave
謝謝@Dave。你能否提供這個答案作爲答案,所以我可以將其標記爲已接受/正確? –