2017-03-26 66 views
0

我试图根据用户输入制作一个领先的点,然后第二个点将在x & y之外50个单位。我认为这个概念应该可以工作,但是我将数组50添加到数组中时遇到了问题。这就是我有和我得到一个类型不匹配:为单个数组值添加值

Set annotationObject = Nothing 
Dim StartPoint As Variant 
leaderType = acLineWithArrow 
Dim Count As Integer 
Dim points(0 To 5) As Double 

StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point") 
MsgBox StartPoint(0) & "," & StartPoint(1) & "," & StartPoint(2) 

StartPoint(3) = StartPoint(0) + 50 
StartPoint(4) = StartPoint(1) + 50 
StartPoint(5) = StartPoint(2) 

Set leader1 = ACAD.ActiveDocument.ModelSpace.AddLeader(StartPoint, annotationObject, leaderType) 
+1

那一行,你得到的错误,当你的错误是什么StartPoint可以的UBOUND? –

+0

它实际上告诉我下标超出范围,我得到它在行StartPoint(3)= StartPoint(0)+ 50 –

+0

我想我得到它感谢您的帮助!我在起点和点之间混合起来 –

回答

1

该线以下的分配与3个元素到可变StartPoint可以,这是变体的阵列。

StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point") 

然后,下面的行尝试向变体StartPoint添加另一个元素。

StartPoint(3) = StartPoint(0) + 50 

但是由于StartPoint已经收到一个带有3个元素的单维数组,所以它的内部表示已经设置好了。 “变量变量维护它们存储的值的内部表示( - 来自微软)。”

试试这个:

Dim StartPoint As Variant 
Dim LeaderPt(8) As Double 'a separate array for leader points 

'Specify insertion point 
StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point") 

'-----Set points for the leader----- 
LeaderPt(0) = StartPoint(0) 
LeaderPt(1) = StartPoint(1) 
LeaderPt(2) = StartPoint(2) 

LeaderPt(3) = StartPoint(0) + 50 '2nd point x coordinate. 
LeaderPt(4) = StartPoint(1) + 50 '2nd point y coordinate. 
LeaderPt(5) = StartPoint(2) 

'add a third point so the last point of the leader won't be set to (0,0,0) 
LeaderPt(6) = LeaderPt(3) + 25  '3rd point x coordinate. Offset from second point 
LeaderPt(7) = LeaderPt(4)   '3rd point y coordinate. Same as the second point 
LeaderPt(8) = LeaderPt(5) 
'--- 


Set leader1 = ACAD.ActiveDocument.ModelSpace.AddLeader(LeaderPt, annotationObject, leaderType)