Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
11 years ago

Saving changes made to variables

I execute the following code from a script to change the value of the variable.



Project.Variable.MyTestVar = "New Variable Value"



This works fine but when i go to close my project I get a popup message asking "Save Change made to the following items?". Is there any way to "Save" this change from the script to avoid this popup?

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    PErsistent variables are specifically designed to persist from run to run.  So, if you set the value in one run, it updates the necessary project files with the new value.    The project itself doesn't save at the end of a run so the Persistent variable value does not get saved until the project is saved.



    If you intend to have a variable that will not be persisted between runs, I'd suggest using the Temporary Variable rather than the Persistent Variable.
  • mfoster711's avatar
    mfoster711
    Regular Contributor
    I want the variable to be persistent. I just want to know how to save the updates made to variable values from a script to avoid the popup window asking "Save Change made to the following items?".
  • Hi Mark.



    This popup message has nothing about TC variables.

    Most likely a project was modified (KDTs or script units were edited) and not saved  then (diskette icon was not clicked).

    TC just asks about saving your work, not variable values.



  • Hi Mark.



    Sorry for misleading answer: I replayd your situation (using userform for variables values setting) and found that popup always appear asking about saving the project.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    As mentioned, the file that saves the value of the persistant variable is a part of the TestComplete project structure.  I believe it's the MDS.tcLS file that is associated with the project.  When you modify the persistent variable value in script, you modify that file.  The file, itself, does not get saved when the script finishes a run.  It is left in a modified but unsaved status.  So, as far as I know, that popup is by design... you are closing the project with files that are not saved yet so you will be prompted whether or not you wish to save them.  I can't see myself (and I could be wrong) a way around this other than executing your project using TestComplete CommandLines and using the /silentmode switch which will auto-save your project at the completion.
  • Hi Mark,

     

    I was trying to do the same thing. The shortcut for saving all is [ Shift+ Ctrl+ S ], so why don't you:

     

    Project.Variable.MyTestVar = "New Variable Value";

    Sys.Desktop.Keys("[Shift][Ctrl][S]");

     

    This might give you warning 'Incomplete Keyboard Input' so disable Log.Message before this code and enable afterwards.

     

    Regards,

    Shiva