简体   繁体   English

在excel VBA中声明函数参数

[英]Declaring function arguments in excel VBA

I have two functions (one of which is called inside the other) which share some variables as arguments, as the following example: 我有两个函数(其中一个在另一个内部调用),它们将一些变量作为参数共享,如下例所示:

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

Is there a way to declare the recurring variables (a, b, and c) only once outside both of these functions, something like this: 有没有办法在这两个函数之外只声明一次重复变量(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

or are those arguments specific to their parent functions? 或者是那些特定于其父函数的参数?

a way to do it, define global variable and don't use them as parameters for your function. 一种方法,定义全局变量,不要将它们用作函数的参数。

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