从VBA中的函数返回数组 [英] return array from function in VBA

查看:2238
本文介绍了从VBA中的函数返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有的,

我想写一个函数来返回一个整数数组,所以我可以为它们建立索引,但我不知道VBA的语法。这里是伪代码:

pre $函数getStats()作为整数
dim returnVal(4)as integer
returnVal(0)= c2percent14
returnVal(1)= c3percent14
returnVal(2)= c4percent14
returnVal(3)= c5percent14
getStats = returnVal
end function
msgbox getStats(3)

这些值都是整数或应该是那么我可以为我想要的统计数据索引返回数组。感谢。



-Rik

解决方案

 函数getStats()作为变体

getStats现在是一个数组而不是一个整数


All,

I would like to write a function to return an array of integers so I can index them, but I am not aware of the syntax for VBA. Here is the pseudo code:

function getStats() as integer
dim returnVal(4) as integer
returnVal(0)=c2percent14
returnVal(1)=c3percent14
returnVal(2)=c4percent14
returnVal(3)=c5percent14
getStats=returnVal
end function
msgbox getStats(3)

where these values are all integers, or should be, and then I can index the return array for the stat that I want. Thanks.

-Rik

解决方案

Function getStats() As Variant

getStats is now an Array and not an Integer

这篇关于从VBA中的函数返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆