Forum Discussion

mfoster711's avatar
mfoster711
Regular Contributor
11 years ago

Setting Default Variable Value from code

Is there any way to set the default variable value for a persistent ProjectSuite, Project or Network variable from a script? 



Seems like the only option from code is setting the local value. I want to be able to set a variable value from within a script and then be able to open my project on a second PC and have that value already set.

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I don't think the Local value (which is what you're looking for) is something that is automatically populated upon copying a project to another drive location.  At least, it only gets populated with what you mark as the "Default" value.



    What I've done in the past is use the Storages object (click here) and used the INI methods.  Every machine, then, that I have configured to run a project has an INI file that is local to that machine so that.  Then, at the beginning of the project, before I run any tests, I read the INI file and populate the local variable values with the values in the INI.



    Hope this helps!
  • mfoster711's avatar
    mfoster711
    Regular Contributor
    I am confused by your reply.  I am not copying a project. I have a project saved on my network drive. I open the networked project in Shared mode on various PCs. Each PC opens the same project.



    I have a form that I use to manage some test variables specific to the applications I am testing. I want to set the variables from PC1 and save to a variable. Then, if I go to PC2 and open the project, I want the variable value I set on PC1 to be there.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Ah, gotcha.  Sorry, I misunderstood your situation.



    I think the problem is essentially going to be the same.  The value of a persistant variable is, I believe, localized.  I don't think it is something that transfers from one PC to another.  What you set the value to on PC1 remains with PC1 and does not transfer to PC2.  The only way I know of (and I could easily be wrong here) to get a value set on PC1 and have it utilized by PC2 is to externalize the value outside of the actual TestComplete project.  Again, using the Storages object (link in previous post) either as an INI file or as an XML where you can read and write values from the file, would be your best way, I believe, to do what you're asking.