Get Object from a Routine of Different Unit
Hi all!
I'm trying to pass the project variables that I set in Unit1 Loop_A into Unit2 Loop_B but I always get an error.
'[Unit1]
Sub Loop_A
Set Var = Project.Variables.varA
End Sub
'[Unit2]
'USEUNIT Unit1
Sub Loop_B
'(How can I get the object "Var" that I set in Unit1 Loop_A?)
End Sub
From the documentation, I only can get how to call/run the routine from different unit. Can I just get the object/value instead of call/run the routine?
Thanks.
Hi,
Three options:
a) Declare Var variable in Unit1 as public/global as suggested by BenoitB. Global variable can be set/get from any function (if its unit is referenced as Benoit demonstrated). Global variables from code units are not the best recommended approach (with possible side effects), so options b) and c)
b) Create one more Project Variable and use it instead of script variable Var;
c) Make Loop_A and Loop_A1 to be not subroutines but functions that return the object referenced by the Var variable.