关于解释变体数组 (VBA/ActiveX) 
从 AutoCAD ActiveX Automation 传回的阵列信息将作为变体传回。 如果您知道数组的数据类型,则可以简单地将变体作为数组进行访问。如果不知道变体中包含的数据类型,请使用 VBA 函数或 .这些函数返回变体中的数据类型。如果需要循环访问数组,可以使用 VBA 语句。VarTypeTypeNameFor Each 计算两点之间的距离下面的代码演示如何计算用户输入的两点之间的距离。在此示例中,数据类型是已知的,因为所有坐标都是双精度坐标。3D 坐标是双精度的三元素数组,2D 坐标是双精度的双元素数组。 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
相关概念 | 
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1   苏公网安备32011402011833)
GMT+8, 2025-11-4 14:04
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.