Link to home
Start Free TrialLog in
Avatar of akohan
akohan

asked on

How to change the result of a function?!


Hello group,

I'm writing a function that reterives number of avaiable macros in an Excel workbook. This works fine but sometimes I need to have this functions the number of avaiable macros in a Workbook and sometimes I want it to return the list or namesof them.

How can I write a functions that its return value could switch from string to integer?

Your help will be appreciated.
Ak

Avatar of dhoffman_98
dhoffman_98
Flag of United States of America image

You can't if the return variable was already declared.

If you don't use OPTION EXPLICIT to force you to declare your variables, then the type of variable returned will be determined by the contents of the variable.

So if you return an alphanumeric value, it will be string, but if you return a whole number it will be an integer.
Avatar of Jorge Paulino
In VB6 ?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
akohan...Why not just always return an array of string and then calculate the count from that array?

Or you could return a Collection object with the names in it...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of akohan
akohan

ASKER


Sorry for later response, have been busy. I know guys you are right it is a bad idea however, I'm going to check all the answers and give you a feedback soon.

As you mentioned, right I believe retruning an array or collection is what we do in other languages as well.

I truly appreciate your help and will get back to you soon.



Thanks,
ak
Avatar of akohan

ASKER



Thanks to all.

Regards,
ak