明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1233|回复: 4

请各位大虾帮忙看一下这个DVB程序错在哪?

[复制链接]
发表于 2004-12-17 16:53:00 | 显示全部楼层 |阅读模式
请各位大虾帮忙看一下这个DVB程序错在哪?
这段绘制抛物线函数曲线程序运行时总是提示:"运行时错误: 方法 'AddLightWeightPolyline' 作用于对象 'IAcadModelSpace' 时失败. Sub Test() Dim p1(0 To 2) As Double
Dim p2 As Variant
Dim pntobj As Variant Dim lobj As AcadLWPolyline
Dim vers(0 To 20000) As Double Dim k As Double
Dim g As Double
Dim b As Double Dim x1 As Double
Dim y1 As Double
Dim x As Double
Dim y As Double
Dim i As Double
Dim a As Double Dim l As Double
Dim m As Double
Dim n As Double
Dim O As Double
Dim P As Double
Dim Q As Double '确定抛物线函数曲线的参数K的值 g = 32.7718 / 1000
b = 68.5036
k = g / (2 * b) '确定抛物线函数曲线的第一点的坐标
l = 100
m = 100
n = 0
p1(0) = l
p1(1) = m
p1(2) = n '提取当前鼠标的动态坐标 p2 = ThisDrawing.Utility.GetPoint(, "p2:") 'p2 = GetPoint
O = p2(0)
P = p2(1)
Q = p2(2) '计算抛物线曲线函数参数X1、Y1的值
x1 = (P - m + k * l ^ 2 - k * O ^ 2) / (2 * k * (l - O))
y1 = m - k * (l - x1) ^ 2 '确定抛物线函数曲线的第一点
vers(0) = l
vers(1) = m i = p1(0)
a = 2 '利用循环确定函数曲线上的端点之间的若干坐标值
If i < p2(0) Then
While i <= p2(0)
x = i
y = k * ((x - x1) * 10) ^ 2 + y1
i = i + 0.5
vers(a) = x
vers(a + 1) = y
a = a + 2
Wend
Else
While i > p2(0)
x = i
y = k * ((x - x1) * 10) ^ 2 + y1
i = i - 0.5
vers(a) = x
vers(a + 1) = y
a = a + 2
Wend
End If '确定抛物线函数曲线的最后一点
vers(a) = p2(0)
vers(a + 1) = p2(1) '利用多义线绘制抛物线+函数曲线
Set lobj = ThisDrawing.ModelSpace.AddLightWeightPolyline(vers) On Error GoTo ErrTrap
Set ehObj = New Hook
ehObj.Enabled = True
ThisDrawing.Utility.GetPoint
ehObj.Enabled = False
Set ehObj = Nothing
Exit Sub

ErrTrap:
ehObj.Enabled = False
Set ehObj = Nothing
End Sub
发表于 2004-12-17 17:09:00 | 显示全部楼层
你的Set ehObj = New Hook


这个Hook是什么?
发表于 2004-12-17 17:28:00 | 显示全部楼层
知道了你把Dim vers(0 To 20000) As Double改为Dim vers(0 To 20001) As Double就行了,呵呵。
 楼主| 发表于 2004-12-17 17:48:00 | 显示全部楼层
多谢指点!现在程序已可以运行成功了。但是,不知为什磨非要写成: Dim vers(0 To 20001)         As         Double的形式?
发表于 2004-12-17 18:57:00 | 显示全部楼层
LightWeightPolyline是二维多段线,vers应该是二维点数组
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 22:26 , Processed in 0.182474 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表