Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long
Dim msg As String
Dim arr1() As String, arr2() As String, arr3() As Date, arr4() As Date, arr5() As Range, arr6() As Range
msg = "arr1 " & IIf(SafeArrayGetDim(arr1) > 0, "数组不为空!", "数组为空!")
arr2 = Split("一、二、三、四、五、六", "、")
msg = msg & vbCrLf & "arr2 " & IIf(SafeArrayGetDim(arr2) > 0, "数组不为空!", "数组为空!")
msg = msg & vbCrLf & "arr3 " & IIf(SafeArrayGetDim(arr3) > 0, "数组不为空!", "数组为空!")
ReDim arr4(1 To 100)
msg = msg & vbCrLf & "arr4 " & IIf(SafeArrayGetDim(arr4) > 0, "数组不为空!", "数组为空!")
ReDim arr6(1 To 256, 1 To 65536)
msg = msg & vbCrLf & "arr5 " & IIf(SafeArrayGetDim(arr5) > 0, "数组不为空!", "数组为空!")
msg = msg & vbCrLf & "arr6 " & IIf(SafeArrayGetDim(arr6) > 0, "数组不为空!", "数组为空!")
MsgBox msg
End Sub
'API判断数组为空或没有初始化
Sub diag()
Dim msg As String
Dim arr1() As String, arr2() As String, arr3() As Date, arr4() As Date, arr5() As Range, arr6() As Range
msg = "arr1 " & IIf(SafeArrayGetDim(arr1) > 0, "数组不为空!", "数组为空!")
arr2 = Split("一、二、三、四、五、六", "、")
msg = msg & vbCrLf & "arr2 " & IIf(SafeArrayGetDim(arr2) > 0, "数组不为空!", "数组为空!")
msg = msg & vbCrLf & "arr3 " & IIf(SafeArrayGetDim(arr3) > 0, "数组不为空!", "数组为空!")
ReDim arr4(1 To 100)
msg = msg & vbCrLf & "arr4 " & IIf(SafeArrayGetDim(arr4) > 0, "数组不为空!", "数组为空!")
ReDim arr6(1 To 256, 1 To 65536)
msg = msg & vbCrLf & "arr5 " & IIf(SafeArrayGetDim(arr5) > 0, "数组不为空!", "数组为空!")
msg = msg & vbCrLf & "arr6 " & IIf(SafeArrayGetDim(arr6) > 0, "数组不为空!", "数组为空!")
MsgBox msg
End Sub