[求助]请高手看看,关于VB调用AutoCAD的,总有错语
<p>代码如下,请各位大哥们看看,最后一句总有问题</p><p>初学这个,不太懂,请各位指教指教!在此谢过!</p><p>Dim Acsdapp As AcadApplication<br/>Private Sub Form_Load()<br/>On Error Resume Next<br/>Set AcadApp = GetObject(, "autocad.application")<br/>If Err Then<br/> Err.Clear<br/> Set AcadApp = CreateObject("autocad.application")<br/>If Err Then<br/> MsgBox ("不能运行AutoCAD")<br/> Exit Sub<br/> End If<br/>End If<br/>AcadApp.Visible = Ture<br/>End Sub</p><p>Private Sub Command1_Click()<br/>Dim a, b As Single<br/>Dim lineobj As AcadLWPolyline<br/>Dim points(0 To 9) As Double<br/>a = Val(Text1.Text)<br/>b = Val(Text2.Text)<br/>points(0) = 0: points(1) = 0<br/>points(2) = points(0) + a: points(3) = points(1)<br/>points(4) = points(2): points(5) = points(3) + b<br/>points(6) = points(0): points(7) = points(5)<br/>points(8) = points(0): points(9) = points(1)<br/>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/>ZoomAll<br/>End Sub</p> <p>ZoomAll?????</p><p>是不是漏了什么???</p> <p>我也不太明白,反正到</p><p>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/>这一句就出问题了</p><p>大家帮我看看啊,到底是那里出问题了</p><p>不胜感激!</p> <p>这是VB模块调用的概念问题,首先要学点VB知识。你执行这个语句,</p><p>用F9将这条语句中断,</p><p>Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)</p><p>在本地窗口中看AcadApp是不是为Nothing,学点VB这个问题很容易解决。</p><p><br/></p> <p> Private Sub Command1_Click()<br/> Dim a, b As Single<br/> Dim lineobj As AutoCAD.AcadLWPolyline<br/> Dim points(9) As Double</p><p> Acadapp = GetObject(, "autocad.application")<br/> If Err.Number Then<br/> Err.Clear()<br/> Acadapp = CreateObject("autocad.application")<br/> If Err.Number Then<br/> MsgBox("不能运行AutoCAD")<br/> Exit Sub<br/> End If<br/> End If</p><p> Acadapp.Visible = True<br/> a = Val(TextBox1.Text)<br/> b = Val(TextBox2.Text)<br/> points(0) = 0 : points(1) = 0<br/> points(2) = points(0) + a : points(3) = points(1)<br/> points(4) = points(2) : points(5) = points(3) + b<br/> points(6) = points(0) : points(7) = points(5)<br/> points(8) = points(0) : points(9) = points(1)<br/> lineobj = Acadapp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)<br/> Acadapp.ZoomAll()<br/> End Sub</p><p></p><p>在VB.NET 2003中调试通过.</p> zdm860114发表于2009-3-14 14:45:00static/image/common/back.gif我也不太明白,反正到Set lineobj = AcadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)这一句就出问题了大家帮我看看啊,到底是那里出问题了不胜感激!<p> 问问题,要问的明白,才能回答的明白,“出问题了”,出什么问题了?错误提示是什么?你没给出来,在我看来,哪代码没什么问题</p> <p>Dim <font color="#ee1196">Acsdapp</font> As AcadApplication <font color="#11ee11">应为</font><font color="#f73809">Acadapp</font><br/>Private Sub Form_Load()<br/>On Error Resume Next<br/>Set AcadApp = GetObject(, "autocad.application")<br/>If Err Then<br/> Err.Clear<br/> Set AcadApp = CreateObject("autocad.application")<br/>If Err Then<br/> MsgBox ("不能运行AutoCAD")<br/> Exit Sub<br/> End If<br/>End If<br/>AcadApp.Visible = Ture<br/>End Sub</p> <p>呵呵,居然是代码敲错了,楼主该好好检查啊。犯这种错误不大应该。</p> <p>还是这里好啊...</p><p>我最近也开始学习VB开发CAD.结果却一懂不懂!</p><p>下面这段代码引自帮助文件上的示例代码..</p><pre class="Code">Sub Example_AddCircle()<br/> ' 该示例在模型空间中创建圆。<br/> <br/> Dim circleObj As AcadCircle<br/> Dim centerPoint(0 To 2) As Double<br/> Dim radius As Double<br/> <br/> ' 定义圆<br/> centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0#<br/> radius = 5#<br/> <br/> ' 在模型空间中创建圆对象<br/> Set circleObj = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)<br/> ZoomAll<br/> <br/>End Sub</pre><pre class="Code"></pre><pre class="Code">结果却弄死也不对.楼主的程序我拿来一用.却对了.哈哈...</pre><pre class="Code">原来这个THISdrawing..要改为Acadapp.Activedocumnet汗...<br/></pre> 对了,Acadapp = GetObject(, "autocad.application"),这一句应该为:set Acadapp = GetObject(, "autocad.application"),否则你创建的应用程序对象无效!<br/>
页:
[1]