What is the difference between Dim and Public in a .vbs file:?
At the top of function libraries variables can be declared before functions are declared.
I know that the Dim variables can be seen with in the .vbs file and also in the functions.
I do notice that if I declare a variable with Dim that I can change the value of the dim in one action and the value is sticky in the next action. I am surprised that I can do this with out using a Public declaration in the .vbs file.
I would think that Dim in the .vbs file would only be visible in the .vbs file. It also can be seen in the calling actions.
My question is why does this work?
VBScript is implemented differently in QTP. The scope of the variable defined in the vbs file is at the test level & therefore is accessible to all actions within a test, even called actions. Public statement isn't relevant in this context.
Dim and Public will have the same impact when used in the associated test libraries. Also you should use Public if you make your intent clear if you want this to be available and used by code in Action, else you should make it Private.
Rajkumar and Tarun,
I appreciate the confirmation of the variable declaration behavior in a .vbs file.