sieben 发表于 2005-8-5 15:52:00

下标越界

<P>Sub Line_Equation(ByRef LParam() As Double, ByVal p1 As Variant, ByVal p2 As Variant)<BR>&nbsp;&nbsp;&nbsp; LParam(0) = p2(1) - p1(1)<BR>&nbsp;&nbsp;&nbsp; LParam(1) = p1(0) - p2(0)<BR>&nbsp;&nbsp;&nbsp; LParam(2) = -1# * LParam(0) * p1(0) - LParam(1) * p1(1)<BR>End Sub</P>
<P>上面是VB代码,我生成DLL文件,然后在VIsual Lisp 中插入</P>
<P>代码如下</P>
<P>(setq dllfile (findfile "d:\\vb\\dll\\linecircle.dll"))<BR>(vlax-import-type-library :tlb-filename dllfile :methods-prefix "LCM-"<BR>&nbsp; :Properties-prefix "LCM-"&nbsp; :constants-prefix "LCM-" )<BR>(setq lcobj (vlax-get-or-create-object "linecircle.calculate"))</P>
<P>(setq arr1 (vlax-make-safearray vlax-vbvariant '(0 . 1)))<BR>(vlax-safearray-fill arr1 '(1.0 1.0 ))<BR>(setq arr2 (vlax-make-safearray vlax-vbvariant '(0 . 1)))<BR>(vlax-safearray-fill arr2 '(2.0 3.0 ))<BR>(vlax-invoke-method&nbsp; lcobj&nbsp; "Line_Equation"&nbsp; 'line1 arr1&nbsp; arr2)</P>
<P>错误如下:</P>
<P>error: Automation Error. 下标越界</P>
<P>其它在VB中没有用到ByRef 的可正常使用</P>
<P>请问是什么问题啊?怎么解决?</P>

efan2000 发表于 2005-8-5 21:45:00

line1没有定义,创建一个0-2的数组,不要赋值试试。

sieben 发表于 2005-8-8 08:38:00

<P>谢谢efan2000!!</P>
<P>(setq line1 (vlax-make-safearray vlax-vbvariant '(0 . 2)))<BR>(setq line1 (vlax-make-safearray vlax-vbdouble '(0 . 2)))<BR>(setq line1 (vlax-make-safearray vlax-vbempty '(0 . 2)))<BR>(setq line1 (vlax-make-safearray vlax-vbobject '(0 . 2)))</P>
<P>我试了好多种数据类型,都不行,出错如下</P>
<P>error: Automation Error. 类型不匹配</P>
<P>后来我加了下面一句还是一样,请帮忙再想想会是什么原因!!!</P>
<P>(setq line1 (vlax-make-variant line1 ))</P>
页: [1]
查看完整版本: 下标越界