为单个数组值添加值

时间:2017-03-26 00:24:43

标签: vba autocad

我正在尝试根据用户输入创建一个领先者,然后第二个点将在x&年。我认为这个概念应该可行,但是我在向数组值添加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 个答案:

答案 0 :(得分:1)

下面的行将一个包含3个元素的数组赋给变量StartPoint,这是一个变体。

  vector<string> vectorOfStrings = {
    "Aa", 
    "Bb", 
    "Cc"
  };

  vector<const char*> vectorOfCStyleStrings(3);

  // convert from string to C style strings
  for (string item : vectorOfStrings)
    vectorOfCStyleStrings.push_back(item.c_str());

  // get vector like a const C style array
  const char* const* arrayOfCStyleStrings = vectorOfCStyleStrings.data();

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

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

但是,由于StartPoint已经收到一个包含3个元素的单个维度的数组,因此已经设置了其内部表示。 &#34;变量变量维护它们存储的值的内部表示(来自微软)。&#34;

试试这个:

StartPoint(3) = StartPoint(0) + 50