且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在同一个模块中将值从一个函数传递到另一个函数

更新时间:2022-10-17 10:14:26

嗨尼克。有几种方法可以将值从一个过程调用转移到下一个过程调用,您使用哪些方法取决于您希望能够访问这些值的范围。


如果希望在特定的子函数或函数中继承变量的最后一个值,可以通过将该变量声明为静态(而不是使用通常的DIM形式)来实现。使用somevar代表变量的名称,sometype代表其类型,静态声明只是:
展开 | 选择 | 换行 | 行号


就是这样。我试过了。但是,当我把它命名为公开时,我正处于一个程序中。我没想到它必须在模块中而不是在程序中。谢谢你一如既往的帮助。


非常感谢


Nick


我是好奇你的陈述由于VBA代码长度的大小限制。你到底指的是什么?


Linq ; 0)>


Hello all,

Due to the size restriction of VBA code length I am forced to seperate my code accross Functions and call to them.

The setup is simple I have a private function that runs...Within that function, based on a recordcount # it then calls a separate function.

The problem I have is that it uses values detemined in the private function to run code is seperate sub.I dont want to reset the values but instead carry them over to the sub it calls.

For instances:
Private Sub ()
vDate = now()
Employee = current employee
Call ShiftRequest

(now as the code runs these values change based on certain criteria)

I would like to have something like this happen:
Public Sub ShiftRequest()
vDate = (private sub value of vDate when called)
Employee = (private sub value of Employee when called)

Can anyone help with how this is done. Or for that matter if it can be done.

Please let me know is this is not clear.

Thank you in advance.

Nick

Hi Nick. There are several ways to carry over values from one procedure call to the next, and which of these you use will depend on the scope in which you want to be able to access the values.

If you wish to carry forward the last value of a variable within a specific Sub or Function you can do so by declaring that variable as Static (instead of using the usual DIM form). Using somevar to stand for the name of a variable, and sometype to stand for its type, a static declaration is just:
Expand|Select|Wrap|Line Numbers


That was it. I had tried that. However, I was in a procedure when I named it public. I didnt think about it having to be in the module but not in a procedure. Thank you for your help as always.

Much appreciated

Nick


I''m curious about your statement " Due to the size restriction of VBA code length." What exactly are you referring to here?

Linq ;0)>


相关文章