vba - VBA:将类型名称作为参数传递(Inventor iLogic)
问题描述
我想创建带有类型检查的函数。
function MyFunc(ByVal Obj As Object, Typ As Type) As Boolean
...
If TypeOf Obj Is typ Then
...
End Function
对于标准类型,比较返回的字符串没有问题,TypeName(Obj)
如下所述:2010 VBA - Pass Type as parameter
但这在 iLogic 中很棘手。有主要类型Document
和派生的“子类型” AssemblyDocument
,DrawingDocument
...
这些子类型中的每一个也是Document
类型。出于我的目的,我对它是什么 Document 子类型不感兴趣。我只需要检查主要Document
类型。
更好地解释一些代码:
Dim Obj As Document
Obj = ThisDoc.Document
Logger.Debug(TypeName(Obj)) ' <-- Returns: AssemblyDocument
Logger.Debug(TypeOf Obj Is Document) ' <-- Returns: True
Logger.Debug(TypeName(ThisDoc.Document)) ' <-- Returns: AssemblyDocument
Logger.Debug(TypeOf ThisDoc.Document Is Document) ' <-- Returns: True
那么,有没有办法将类型传递给函数,或者是获取可能子类型列表并将它们逐项与字符串结果进行比较的唯一方法TypeName(Obj)
?
解决方案
推荐阅读
- mysql - mysql中的MongoDB oid
- java - 如何在空白单元格上设置颜色
- ag-grid - Ag-Grid 不支持特殊符号
- javafx - 拖放在 Java 11 和 Java 8 中的工作方式不同
- qt - 如何在 Android 上使用 QT 快速应用程序获取 WiFi 名称
- java - Ask vs Tell or forward for Actors using Akka Streams
- c# - c# 中的存储过程输出参数返回 Empty where as Working fine while Executing in SQL
- android - 到处都是missingDimensionStrategy - 没有更好的方法吗?
- laravel - laravel - Vuejs 路由与 Laravel 路由冲突,试图发出 axios 请求
- java - 用maven构建的jar文件找不到配置文件