Function Returning Two Values?

J

JJ

I have a function which counts tasks based on certain criteria A, B,
and C.

The same function is also used to count tasks based on criteria A, B,
C, and D. This is done by setting a Boolean argument to True or False
depending on whichever is needed.

Therefore, the second set of is a subset of the first set.

This function looks at either the entire Project file or just user-
selected tasks.

In order for me to get both results I have to run the function twice,
which requires me to run through the entire set of tasks twice.

Is it possible to run through this function once and return both sets
of numbers?

If so, how? Use an array? Can a function return an array? Is there a
better way?

I want to be as efficient as possible because some Project files have
3000+ tasks.

Thanks!
 
R

Rod Gill

Hi,

The simplest way is for the function to store its results in two global
variables (Dim at the top of the module outside any Sub or Function). That
way any Sub can read or write to them. The Function can be a Sub then unless
you return a success/fail flag.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
J

JJ

Thanks Rod! As always, I can always count on you for a solution. I
ended up having to make a global variable rather than a module-level
variable because the form calls a subroutine in another module. Either
way... it works fine.

Thanks again!
 
R

Rod Gill

Glad I could help!

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com



Thanks Rod! As always, I can always count on you for a solution. I
ended up having to make a global variable rather than a module-level
variable because the form calls a subroutine in another module. Either
way... it works fine.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top