Forum Discussion

praveensqa's avatar
praveensqa
Contributor
13 years ago

Global variable declaration

Hi All,

How to declare a variable as Global; Because i want to use the that variable and assigned value in all the test scripts(Total Project functions).



Regards,

Praveen P.
  • Thanking you. 

    Yes. But i have the scenario like this



    Unit is Te2

    'USEUNIT Te3   


    Sub pro

       dim va

     

       Va=10

      

     End Sub



    Unit is Te3

    'USEUNIT Te2 


    Function Te3

      Te2.pro// for calling Te2 Pro--- Fine.

         \\ Here i need to get the Va variable value from unit Te2

          if i type Te2.Va--- Ok, but while execute the test i am getting object doesn't support the Exception is coming.



        How i will get Va value in this unit. is there any method?





      End Function



    Regards,

    Praveen



  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Praveen,



    To access the Va variable defined in the Te2 unit using the Te2.Va syntax, you need to define this variable outside of any routines, so that it has the global scope (rather than the local scope to the pro routine):

    Dim Va



    Sub pro

      Va = 10

    End Sub




    Alternatively, you can create the Va variable as a project variable (in Tools > Current Project Properties > Variables); in this case, you can use this variable like this:



    Unit Te2:

    'USEUNIT Te3   



    Sub pro

      Project.Variables.Va = 10

    End Sub


    Unit Te3:

    'USEUNIT Te2



    Function Te3

      Te2.pro

      Log.Message Project.Variables.Va

    End Function
  • Thanking You Helen Kosova. It is very use full to me. Now i am able to access that Variable in all the Units.
  • Hello,



    Are non-project global variables visible across different scripts?



    I've created a global scope variable in one script,



    Dim testVar : testVar = "test"



    However, the following sub in another script does not see the variable:



    Sub CheckVar

    Log.Message testVar

    End Sub



    I've set up the project in such a way, that it runs CheckVar at start.