CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于解释变体数组 (VBA/ActiveX)

2023-1-5 03:03| 发布者: admin| 查看: 716| 评论: 0|来自: AutoCAD

摘要: 从 AutoCAD ActiveX Automation 传回的数组信息将作为变体传递回去。

从 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

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 12:10

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部