I recently discovered this way of doing in VBA, you populate a function value by passing it as an argument of another function, and then, when the parameter of this other function is filled, its link to the first function value.
EDIT FOR CLARIFICATION : This idea explained by the teacher was that sometimes, you have a complicated function and then we can extract several informations from the result. And those functions are meant to be used in excel, so instead of letting people calling the complicated one, you create "dummy" functions, like result1 et and result2, and it will be filled with the value we want.
Here is the code (edited, i forget things sorry):
Function f(* a lot of parameters *, Optional result1 As Variant, Optional result2 as Variant) as Boolean
raw_result = * a lot of calculus *
result1 = raw_result
result2 = -raw_result
f = True
End Function
Function result1(* same parameters than f *) as Double
' I will give result1
Call f(* same parameters than f *, result1)
End Function
Function result2(* same parameters than f *) as Double
'Two coma on purpose to access the second optional parameters
Call f(* same parameters than f *,, result2)
End Function
Here, if i do result1(* same parameter than f*)
, it will give me raw_result
value.
What is the theory behind this concept, how does it work and is it only a VBA thing ?