AutoCAD ActiveX オートメーションから返される配列情報は、バリアントとして返されます。
配列のデータ タイプが分かっていれば、バリアントには配列と同様に簡単にアクセスできます。バリアントに含まれる配列のデータ タイプが不明の場合は、VBA 関数 VarType または TypeName を使用します。これらの関数は、バリアント内のデータ タイプを返します。配列を繰り返す必要がある場合は、VBA の For Each 文を使用することができます。
次のコードは、ユーザが入力した 2 点間の距離を計算する例を示しています。この例では、すべての座標が倍精度浮動小数点なので、データ タイプは明らかです。3D 座標は 3 要素の倍精度浮動小数点配列で、2D 座標は 2 要素の倍精度浮動小数点配列です。
Sub Ch2_CalculateDistance()
Dim point1 As Variant
Dim point2 As Variant
' Get the points from the user
point1 = ThisDrawing.Utility.GetPoint _
(, vbCrLf & "First point: ")
point2 = ThisDrawing.Utility.GetPoint _
(point1, vbCrLf & "Second point: ")
' Calculate the distance between point1 and point2
Dim x As Double, y As Double, z As Double
Dim dist As Double
x = point1(0) - point2(0)
y = point1(1) - point2(1)
z = point1(2) - point2(2)
dist = Sqr((Sqr((x ^ 2) + (y ^ 2)) ^ 2) + (z ^ 2))
'Display the resulting distance
MsgBox "The distance between the points is: " _
& dist, , "Calculate Distance"
End Sub