加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

【EXCELVBA】带返回值的Function

(2018-09-10 20:59:17)
分类: OFFICE办公
http://s13/mw690/002aDYHtzy7nwwMv6r22c&690        在VBA中,Function的返回值是通过函数名返回的,即“返回值=函数名”。
          一、返回值为一个值的Function,例如:
         Function getResult(ByVal x As Byte, ByVal y As Byte) As Byte
           getResult = x + y
         End Function
       
         Sub Test()
             Dim res As Byte
             res = getResult(5,10)
             MsgBox (res)
         End Sub
         二、返回值为多个值的Funtion,使用数组保存返回值,例如:
         Function getResult(ByVal x As Byte, ByVal y As Byte) As Byte()
              Dim tmpRes(1 To 2) As Byte
              tmpRes(1) = x + y
              tmpRes(2) = x * y
              getResult = tmpRes()
         End Function

         Sub Test()
             Dim arr(1 To 2) As Byte
             res = getResult(5, 10)
         End Sub

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有