Forum Discussion

rajesh_chidamba's avatar
rajesh_chidamba
Occasional Contributor
10 years ago

Temproary Variables Declaration

Hi 



I am a newbie to Test Complete. i have certain question that could help me to understand variables declaration with. (I am a Expert at QTP so if you could map anythign with QTP would be also more easy to understand)



1) I tried using Environment Variable in QTP , the sma eway i tried project and projectsuite variables in Test Complete, but i have the fllowing doubts



                                      1- Environmentvariabels in QTP holds the value for the Particular run session, when the script stops it does not hold any value. (in short The scope is for every run session. there are enviornment variables which are constant which could be changed in Settings page and throught script too), But the projetc Variabels which i create at run time are getting it into the persistent varaible section of the project or project suite, so it stays for a every session with the same value with it for every run.

                                     2 -  i just need to reset the values from the project or project suite variables section on the whole not by providing every varialbe name but if you have any option in script which could remove all variable or remove all variable values.(i dont want to have even any default variable or values, i am ready to create and delete variables and assign values at run time by script)



Please provide a code snippet . plesae find the code snippet for QTP below.



For QTP : Environment.value("TempVar") = "AAAAA" - this is created by the user at run time and it vanished at the end of the session.



Environment.value("OS") = "Windows XP" - This is the default variables or system info provided by QTP for the user to use it right away without need to write any code. which could be changed from the User defined Enviornment from the QTP settings.



Awaiting your Reply.



Thanks

RC





5 Replies

  • rajesh_chidamba's avatar
    rajesh_chidamba
    Occasional Contributor
    Hi All



    Thanks for all your Reply. I found the answer and it solved my problem. Here is the code snippet. its Simple :-)



    This would reset all the values that I have in persistent variable list. so can enter new variable values all the time



    Function Sample()

    intvalue = Project.Variables.VariableCount

      For i= 0 to intvalue-1

        strvariablesname = Project.Variables.GetVariableName(i)

        Project.Variables.VariableByName(strvariablesname) = ""

      Next

    End Function



    This Function would remove all the variables in the persistent variable section, hope this helps for other newbie's too.



    Function Sample2()

    intvalue = Project.Variables.VariableCount

      For i= 0 to 100

        If Cint(Project.Variables.VariableCount) = 0 Then Exit For

        strvariablesname = Project.Variables.GetVariableName(i)

        Project.Variables.RemoveVariable strvariablesname

      Next

    End Function



    Thanks again for all your reply.



    Thanks

    RC

  • murugans1011's avatar
    murugans1011
    Regular Contributor
    Hello,



    Project has temporary and persistent variable. temporary variable holds value at runtime. where as persistent has value even after test run. so in ur case use temporary variable to acheive the task.



    To acces project variable from script u can use



    project.variables.varName=0



    To add variables through scripts

    [VBS]

     Set Variables = Project.Variables

      if Not  Variables.VariableExists("Var1") then

          Project.Variables.AddVariable "var1", "Integer"   'datatype

      End if



    To remove variable

      project.variables.removevariable "variablename"



    See for more info
  • rajesh_chidamba's avatar
    rajesh_chidamba
    Occasional Contributor
    hi 



    Thanks for the reply , still i haven't got the answers.



    In short 



    1) I am trying to load the variables from Excel to Project variables everytime when the scripts starts, so i need a temp variable which should loose everything once scripts stops.

    2) If the Above is not possible i should be able to atleast reset all the values in project.variables so that i will check the variable exist and then load the new variables alone without using a variable name as it will change for every run.



    The above are used to create dynamic variable and set values to them and use it and create another set and try to use it , without having lots of variables in project or project suite.(resetting everything)



     please provide me scripts . i tried using it Table to get temprorary variable but i was not able to , as its entirely different storage type than what i need.



    Thanks

    RC
  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    Why not just read your data in from the Excel sheet as you go and skip the variables altogether?