繁体   English   中英

VBScript字符串数组-错误800A000D类型不匹配

[英]VBScript Array Of Strings - Error 800A000D Type Mismatch

我在处理由AutoCAD中方法调用返回的字符串的Variant数组时遇到麻烦。 返回的数组看起来很粗糙,但是当我尝试引用该数组中的元素,甚至在For Each语句中包含该数组的名称时,都会收到Type Mismatch错误

这是代码:

Dim acApp 'As AutoCAD.AcadApplication
Dim acDoc 'As AutoCAD.AcadDocument
Dim acLyt 'As AutoCAD.AcadLayout

'Get the AutoCAD application...
On Error Resume Next
Set acApp = GetObject(, "AutoCAD.Application")
On Error GoTo 0
If (acApp Is Nothing) Then
  Set acApp = CreateObject("AutoCAD.Application")
End If

'Is there a drawing open? If not we'll need to open a new drawing...
If acApp.Documents.Count > 0 Then
  Set acDoc = acApp.ActiveDocument
Else
  Set acDoc = acApp.Documents.Add
End If

'Get a reference to the Model Space layout (always first)...
Set acLyt = acDoc.Layouts(0)

'Get the list of canonical media names ("A4", "A3" etc) for the plot device for this layout...
'The AutoCAD documentation says that this method returns a variant, which is an array of strings,
'which seems to be what is actually returned.'
'However, I can't reference the array elements without producing a "Type Mismatch" error.

Names = acLyt.GetCanonicalMediaNames()

WScript.Echo VarType(Names) 'This line runs ok, and returns 8200, which is 8192 for Variant Array, + 8 for String.
WScript.Echo Names(0) 'This line generates the error...

我感到困惑,所以任何帮助将不胜感激。

保罗

至少有两个StackOverflow问题,其答案表明VBScript仅能处理从COM对象返回的变量数组。 如果AutoCAD确实返回了一个字符串数组,则可能无法在VBScript中使用该数组(假设没有办法让AutoCAD更改其COM接口)。

参考文献:

它可能是一个多维数组。 使用UBound测试:

Ubound(Names, 1)  ' Number of Columns
Ubound(Names, 2)  ' Number of Rows

或更多(最多32个)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM