2017-03-26 62 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)