如例:Type typeA
    a as Integer
end Type要求函数如下的格式:
public function getArr() as {typeA的数组}
end function或者这样,便ta=typeA的数组,然后返回:
public function getArr2(byval ta)
end function
应该怎么实现?

解决方案 »

  1.   

    可以用过程直接用类型数组的引用,来直接返回..
    比如
    Type typeA
        a as Integer
    end Typepublic sub getArr(byref type() as typeA) 
           '对type的操作,付值或修改..
          for i =0 to 10
             type(i).a = i
          next
    end subprivate sub command1_click
     dim mytype(10) as typeA '这个就是要返回的类型数组
        getArr mytype()      '等效于函数返回类型数组.
       for i = 0  to 10    
        debug.print mytype(i).a
       next
    end sub也可以用集合来处理
      

  2.   

    我发现我打错了几个地方,呵呵
    “或者这样,便ta=typeA的数组”应该是“或者这样,使ta=typeA的数组”
    “public function getArr2(byval ta)”应为“public function getArr2(byref ta)”烦请再回答一个问题:函数自定义类型的数组这种形式是不是不可能实现的?
      

  3.   

    You can use the name of a Function or Property Get procedure as
    a local variable anywhere in the procedure. If your procedure
    returns a String or UDT type, writing directly to the function name
    instead of a temporary variable saves you from making a full copy
    of your data at the end of a function. Unfortunately, you can’t
    leverage this technique if your function returns an array, because
    VB interprets any parentheses after the function name as a call to
    the function, not as an index into the array. The overloaded
    parentheses force you to use a local variable and make an expensive
    array copy at the end of the function. However, if the assignment
    to the function name happens on the statement before an
    [End|Exit] [Function|Property], then VB simply transfers ownership
    of the local variable to the function name instead of copying
    it. Any intervening statements (including End If) preclude the
    compiler from making this optimization.