Forum Discussion

Josh_147's avatar
Josh_147
Contributor
4 years ago
Solved

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 '[U...
  • AlexKaras's avatar
    AlexKaras
    4 years ago

    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.