# Controlling the Startup State of a Deployed Project

As you develop your Designer application, you will typically switch between development mode, where you use the Cognex Designer Integrated Development Environment to write script code, configure Tasks, and design HMI pages, and Test Mode, where you interactively test your application.

It is important to remember that whatever changes you make to your application state while you are in Test Mode remain in effect when you return to development mode. Because of this, it can be easy to inadvertently save temporary changes to your project.

For example, suppose your application includes a Page CheckBox control. If you enter Test Mode and check the CheckBox, then return to development mode and save your application, the state of that checkbox will be saved as well. If you then deploy the application, it will always start with that checkbox checked.

1. You can explicitly establish the startup state of your application's tags and Page elements by adding code to your application's OnStartup script to initialize those items, as shown below (you can also use Recipes for the same purpose):

       // Initialize tag values
       $myRect = null;

       // Initalize HMI control states
       $Pages.Page.Checkbox.State = false;
       $Pages.Page.ResidualError.Text="0.0";
       $Pages.Page.xText.Text = $Pages.Page.yText.Text = "0";

2. To set the startup state of VisionPro Tool Blocks in Tasks, you can use code in the OnStartup script to load the state of a tool block from a persisted .VPP file. To do this, start by using the Export ToolBlock button in the tool block editor to save the state of the tool block to a .VPP file.

1. Next, to allow script code to set the state of the tool block through a tag, open the VisionPro Tag Manger and check the Expose ToolBlock checkbox.

2. Once you have performed these steps, adding the following code to your application's OnStartup script will initialize the tool block based on the saved state:

       // Load toolblock state from saved .VPP file
       $Tasks.CopyRegion.Task.myToolBlock.ToolBlock = CogSerializer.LoadObjectFromFile($System.Info.ProjectPath + "\\Data\\tbstate.vpp") as CogToolBlock;

Tip:

- As shown in the preceding example, if you save the .VPP file into the Data folder in your project folder, you can use the $System.Info.ProjectPath function to specify the location of the file for loading. This path will be automatically resolved so that it is also valid when you deploy your application.
- If you want all tags to revert to default, delete {DeployedFolder}\Data\runtime.db3