VB API判断数组为空

1.

'API判断数组为空或没有初始化

Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef saArray() As Any) As Long  

Private Sub Command1_Click()
Dim tmp() As String
If SafeArrayGetDim(tmp) = 0 Then
MsgBox "数组为空或没有初始化"
End If
End Sub

 

2.

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (

                                                                              Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long

Private Sub Form_Load()
    Dim S() As Long                                            //动态数组
    Dim VarPtrArrayAddress As Long                 //对数组用函数VarPtrArray得到的地址
    Dim SafeArrayPoint As Long                         //'SafeArray结构的指针的值
    
    VarPtrArrayAddress = VarPtrArray(S)

    CopyMemory SafeArrayPoint, ByVal VarPtrArrayAddress, 4   //没有分配内存,这时候SafeArrayPoint的值为0
    If SafeArrayPoint = 0 Then
        MsgBox "空"
    End If

End Sub

转载于:https://www.cnblogs.com/rosesmall/p/6398115.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 UG/NX 的二次开发中,可以使用 NXOpen API判断一个圆柱面是否是通孔。以下是使用 VB.NET 实现的示例代码: ```vb.net Imports NXOpen Public Class Program Public Shared Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work ' 获取选中的圆柱面对象 Dim selectedEdges() As Edge = SelectEdges(workPart) ' 判断圆柱面是否是通孔 For Each edge As Edge In selectedEdges If IsThroughHole(edge) Then Console.WriteLine("The cylinder face is a through hole.") Else Console.WriteLine("The cylinder face is not a through hole.") End If Next Console.ReadLine() End Sub ' 选择圆柱面边 Public Shared Function SelectEdges(ByVal workPart As Part) As Edge() Dim prompt As String = "Select edges:" Dim title As String = "Select Edges" Dim scope As Selection.SelectionScope = Selection.SelectionScope.Edge Dim selection As Selection.Response = Nothing Dim selectionMask_array(0) As Selection.MaskTriple selectionMask_array(0) = New Selection.MaskTriple(scope, Selection.SelectionType.Edge, Selection.ActionType.ClearAndEnableSpecific) selection = workPart.UserSelectionManager.SelectObjects(prompt, title, selectionMask_array) Dim selectedEdges() As Edge = Nothing If selection.ResponseCount > 0 Then Dim response_array() As Selection.Response = selection.ToArray() ReDim selectedEdges(response_array.Length - 1) For i As Integer = 0 To response_array.Length - 1 Dim response As Selection.Response = response_array(i) selectedEdges(i) = CType(response.Object, Edge) Next End If Return selectedEdges End Function ' 判断圆柱面是否是通孔 Public Shared Function IsThroughHole(ByVal edge As Edge) As Boolean Dim isThroughHole As Boolean = False ' 判断边是否为圆柱面 If edge.SolidEdgeType = Edge.EdgeType.Cylindrical Then ' 获取边的法向量 Dim normal As Vector3d = edge.GetFace().GetFaceNormal() ' 判断法向量是否与边的方向相反 If normal.Dot(edge.GetCurve().Direction) < 0 Then isThroughHole = True End If End If Return isThroughHole End Function End Class ``` 在这个例子中,我们首先获取当前工作部件 `workPart`,然后通过 `SelectEdges` 方法选择圆柱面边。`SelectEdges` 方法中,我们使用 NXOpen API 提供的选择器来选择边对象,并将选中的边存储在 `selectedEdges` 数组中。 接下来,我们通过调用 `IsThroughHole` 方法来判断每个边是否是通孔。`IsThroughHole` 方法中,我们首先判断边的类型是否为圆柱面(`Edge.EdgeType.Cylindrical`),然后获取圆柱面边所在面的法向量和边的方向向量。如果法向量与边的方向相反,则判定为通孔。 最后,根据判断结果输出相应的信息。 请注意,以上代码仅为示例,具体实现可能需要根据你的具体需求进行调整。另外,在使用 NXOpen API 进行二次开发时,确保正确引用相关的 NXOpen 和 NXOpen.UF 命名空间。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值