Public Life Time and Scope
Is there any difference if a variable is defined as Public in an Action or in attached library files?
In both cases the Public is defined out side of any functions. It is usually at the top of the action or library file and looks like:
I think it should be the same. I am not sure.
If it's public in an action, then the variable is only available in that action. If it's declared as public in an associated library then it should be available to all actions and functions. For example, if you declare a variable in Action1 and then call a function in a library, the function cannot see that variable unless you pass it as a parameter.
I was noticing this but I was a bit afraid to ask about it. I thought that if I was wrong people would be wondering why I am asking a silly question. I'm glad that I asked.
One of my observations is that I declared a variable Public in an Action. Then I declared the same one as a Dim in the library. There was no complaint form UFT. It makes sense now.
I was using the variable to hold an object/class. There was an added level of confusion with having to instantiate the class inside of the same place the Class is defined.
I have code working using the two time declaration. I should be able to move the Public to a file and then only have to define it once. I wonder if I can declare the Public in the same library where I define the class.
Last edited by bklabel1; 01-09-2015 at 06:08 AM.
Reason: I used the word object instead of User Defned variable.