请教各位大侠:这段程序为什磨总出现“类型不匹配”的错误?
请各位大侠帮忙看一下这段程序:为什磨运行时总是出现“错误13:类型不匹配!”的错误?'----------------------------------------------
Sub Test()<BR>On Error Resume Next<BR>Dim a As Variant<BR>Dim c(2) As Double<BR>Dim d As Double
c(0) = 100<BR>c(1) = 100<BR>c(2) = 0
<BR>Do While 1<BR><FONT color=#42e61a> </FONT><FONT color=#2bd54d> ' 将鼠标的当前坐标值赋值给a</FONT><BR> a = GetPoint<BR> d = ((c(1) - a(1)) ^ 2 + (c(0) - a(0)) ^ 2) ^ 0.5<BR> ThisDrawing.Utility.Prompt d & vbCrLf<BR> <BR> Select Case a(2)<BR> Case -1<BR> Exit Sub<BR> Case 0<BR> Case 1<BR> End Select<BR>Loop<BR> <BR>End Sub<BR>Function GetPoint()<BR><FONT color=#22dd22>'功能:返回当前鼠标状态<BR>'返回值:一维数组<BR>'返回0,0,-1表示按下鼠标左键,返回0,0,1表示按下鼠标右键,返回a,b,0表示当前鼠标坐标<BR></FONT>On Error GoTo ErrClear<BR>Dim obj As VLAX<BR>Dim pRetVal(2) As Double, retVal<BR>Set obj = New VLAX<BR>obj.EvalLispExpression ("(setq a (grread t) b (car a) c (cadr a))")<BR>Select Case obj.GetLispSymbol("b")<BR>Case 3<BR>pRetVal(2) = -1<BR>Case 5<BR>retVal = obj.GetLispList("c")<BR>pRetVal(0) = retVal(0)<BR>pRetVal(1) = retVal(1)<BR>Case Else<BR>pRetVal(2) = 1<BR>End Select<BR>GetPoint = pRetVal<BR>ErrClear:<BR>Set obj = Nothing<BR>End Function<BR>'----------------------------------------------------------- 有没有使用VLAX类? 我已经将您编写的VLAX.CLS导入到该程序的类模块中.
'----------------------------------------------
' VLAX.CLS v2.0 (Last updated 8/1/2003)<BR>' Copyright 1999-2001 by Frank Oquendo<BR>'<BR>' 该程序由明经通道修改支持2004版本<BR>' <A href="http://www.mjtd.com/" target="_blank" >http://www.mjtd.com</A><BR>'<BR>' Permission to use, copy, modify, and distribute this software<BR>' for any purpose and without fee is hereby granted, provided<BR>' that the above copyright notice appears in all copies and<BR>' that both that copyright notice and the limited warranty and<BR>' restricted rights notice below appear in all supporting<BR>' documentation.<BR>'<BR>' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH<BR>' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY<BR>' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. THE AUTHOR<BR>' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<BR>' UNINTERRUPTED OR ERROR FREE.<BR>'<BR>' Use, duplication, or disclosure by the U.S. Government is subject to<BR>' restrictions set forth in FAR 52.227-19 (Commercial Computer<BR>' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<BR>' (Rights in Technical Data and Computer Software), as applicable.<BR>'<BR>' VLAX.cls allows developers to evaluate AutoLISP expressions from<BR>' Visual Basic or VBA<BR>'<BR>' Notes:<BR>' All code for this class module is publicly available througout various posts<BR>' at <A href="news://discussion.autodesk.com/autodesk.autocad.customization.vba" target="_blank" >news://discussion.autodesk.com/autodesk.autocad.customization.vba</A>. I do not<BR>' claim copyright or authorship on code presented in these posts, only on this<BR>' compilation of that code. In addition, a great big "Thank you!" to Cyrille Fauvel<BR>' demonstrating the use of the VisualLISP ActiveX Module.<BR>'<BR>' Dependencies:<BR>' Use of this class module requires the following application:<BR>' 1. VisualLISP
Private VL As Object<BR>Private VLF As Object
Private Sub Class_Initialize()<BR> '根据AutoCAD的版本判断使用的库类型<BR> If Left(ThisDrawing.Application.Version, 2) = "15" Then<BR> Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")<BR> ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then<BR> Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")<BR> End If<BR> <BR> Set VLF = VL.ActiveDocument.Functions<BR>End Sub
Private Sub Class_Terminate()<BR> '类析构时,释放内存<BR> Set VLF = Nothing<BR> Set VL = Nothing<BR>End Sub
Public Function EvalLispExpression(lispStatement As String)<BR> '根据LISP表达式调用函数<BR> Dim sym As Object, ret As Object, retVal<BR> Set sym = VLF.Item("read").funcall(lispStatement)<BR> <BR> On Error Resume Next<BR> <BR> retVal = VLF.Item("eval").funcall(sym)<BR> <BR> If Err Then<BR> EvalLispExpression = ""<BR> Else<BR> EvalLispExpression = retVal<BR> End If<BR>End Function
Public Sub SetLispSymbol(symbolName As String, value)
Dim sym As Object, ret, symValue<BR> symValue = value<BR> <BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> <BR> ret = VLF.Item("set").funcall(sym, symValue)<BR> EvalLispExpression "(defun translate-variant (data) (cond ((= (type data) 'list) (mapcar 'translate-variant data)) ((= (type data) 'variant) (translate-variant (vlax-variant-value data))) ((= (type data) 'safearray) (mapcar 'translate-variant (vlax-safearray->list data))) (t data)))"<BR> EvalLispExpression "(setq " & symbolName & "(translate-variant " & symbolName & "))"<BR> EvalLispExpression "(setq translate-variant nil)"<BR>End Sub
Public Function GetLispSymbol(symbolName As String)
Dim sym As Object, ret, symValue<BR> symValue = value<BR> <BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> <BR> GetLispSymbol = VLF.Item("eval").funcall(sym)<BR>End Function
Public Function GetLispList(symbolName As String) As Variant<BR> Dim sym As Object, list As Object<BR> Dim Count, elements(), i As Long<BR> <BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> Set list = VLF.Item("eval").funcall(sym)<BR> <BR> Count = VLF.Item("length").funcall(list)<BR> <BR> ReDim elements(0 To Count - 1) As Variant<BR> <BR> For i = 0 To Count - 1<BR> elements(i) = VLF.Item("nth").funcall(i, list)<BR> Next<BR> <BR> GetLispList = elements<BR>End Function
Public Sub NullifySymbol(ParamArray symbolName())
Dim i As Integer<BR> <BR> For i = LBound(symbolName) To UBound(symbolName)<BR> EvalLispExpression "(setq " & CStr(symbolName(i)) & " nil)"<BR> Next<BR>End Sub
'------------------------------------------------------ 最好整个Do While循环用Lisp实现,再用VBA利用VLAX类调用,否则过不了一会就会崩溃掉 飞狐老兄:请给出详细的程序代码,好吗? <A href="http://www.vba.cn/bbs/dispbbs.asp?boardid=4&star=1&replyid=21264&id=20448&skin=0&page=1" target="_blank" >http://www.vba.cn/bbs/dispbbs.asp?boardid=4&star=1&replyid=21264&id=20448&skin=0&page=1</A> 大侠:我想知道为什磨在程序执行到:
d = ((c(1) - a(1)) ^ 2 + (c(0) - a(0)) ^ 2) ^ 0.5<BR>
时总是出现“运行错误13:类型不匹配”? 频繁调用GetPoint函数会引发错误,而GetPoint函数内错误处理的结果是a为Null
页:
[1]