繁体   English   中英

在excel VBA中声明函数参数

[英]Declaring function arguments in excel VBA

我有两个函数(其中一个在另一个内部调用),它们将一些变量作为参数共享,如下例所示:

Public Function f1(a as Double, b as Double, c as Double)
"code"
End

Public Function f2(a as Double, b as Double, c as Double, t as Integer)
var = f1(a, b, c)
"code"
End

有没有办法在这两个函数之外只声明一次重复变量(a,b和c),如下所示:

Dim a As Double, b As Double, c As Double

Public Function f1(a, b, c)
"code"
End

Public Function f2(a, b, c, t as Integer)
var = f1(a, b, c)
"code"
End

或者是那些特定于其父函数的参数?

一种方法,定义全局变量,不要将它们用作函数的参数。

Dim a As Double, b As Double, c As Double

Public Function f1()
"code use a,b and c"
End

Public Function f2(t as Integer)
var = f1()
"code use a,b and c"
End

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM