我可以在不同模块的两个私有函数之间传递变量吗?

时间:2019-05-15 08:50:09

标签: vba

我在两个不同的模块中有两个私有函数。这两个函数应该共享一个公共变量。我应该如何进行编程?

当前代码是这样:

Private function TestFunction1 (ByVal traffic as string) As Boolean
'snippet from the code
dim amount as string
amount = inputbox("Fill in amount")
end function

Private Function TestFunction2 (ByVal layout as string) as Boolean
'snippet from the code
dim result as string
result = "the amount is: " & amount
end function

我知道这不是一个正确的函数,但这只是代码的一部分。由于业务规定,我无法共享整个代码。 我应该如何将金额传递给另一个模块中的另一个函数?

谢谢

1 个答案:

答案 0 :(得分:0)

当然,可以通过将amount变量声明为Public来实现:

Public amount As Long 'not sure why you declared it as a string, as it seems to be a number

Private function TestFunction1 (ByVal traffic as string) As Boolean
    'snippet from the code
    amount = inputbox("Fill in amount")
End Function