VBScriptやVBAの配列が初期化されているか? 配列の次元数は?
VBScriptやVBAでは、以下のようにLBound()のエラーを拾う。のが普通のやり方みたいです。
Function NumberOfDimensions(a)
NumberOfDimensions = -1
On Error Resume Next
Do
NumberOfDimensions = NumberOfDimensions + 1
If LBound(a, NumberOfDimensions + 1) Then:
Loop Until Err
End Function
ここで、次元数=0が、「配列が初期化されてない。」の意味です。
ところで、JScriptには、そういうメソッドがあります!えっ?
Function NumberOfDimensions(a)
Dim sc As Object
Set sc = CreateObject("ScriptControl")
sc.Language = "JScript"
sc.AddCode "function NumberOfDimensions(a){return new VBArray(a).dimensions();}"
NumberOfDimensions = sc.CodeObject.NumberOfDimensions(a)
End Function