Variable number of arguments in ParamArray ArgList()

前提是你 提交于 2020-01-03 04:14:07

问题


If I want to pass a number of values for the ParamArray arglist via an array, how do I do it? From what I've read so far, on VBA, it appears that I need to explicitly list the values that I want to pass. But what if there are potentially different numbers of values to pass, so I do not know in advance how many I'll want to pass to the function? Is there not some way of using an array (a one-dimensional array) with a variable dimension?


回答1:


There are several ways to achieve that:

  • dimension the array to be larger than you require, keep a count of how many items actually get added and then Redim Preserve back to the correct size
  • use a Collection object instead (as a normal parameter rather than a ParamArray)



回答2:


You can pass a variable number of values to a function if the function includes a Param Array:

http://msdn.microsoft.com/en-us/library/538f81ec(v=VS.71).aspx

http://msdn.microsoft.com/en-us/library/aa164809(v=office.10).aspx



来源:https://stackoverflow.com/questions/949263/variable-number-of-arguments-in-paramarray-arglist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!