Support Statement: How can I automatically edit a VBP file?

Q: How can I edit a VBP file as part of my migration process?
A: Use the EditFile command in a GlobalSettings file.

Overview

gmStudio has a preprocessor that allows editing source codes in memory before they are translation. This preprocessor is controlled by Compile/Fix commands. However, the preprocess cannot be used to edit the VBP file because the VBP is processed before the standard pre-processor runs.  In order to edit a VBP file, you must use a Refactor/EditFile command in a GlobalSettings file.  The steps for setting this up are shown below.   In this example, the objective is to remove unused files from the translation process so they do not become part of the translation results. This not only results in a cleaner result, but also simplifies requirements gathering for subsequent analysis and translation tuning work since time is not wasted on files that are not important to the project.

Steps for editing a VBP using GlobalSettings

1) Add a GlobalSettings file to your your upgrade project file


a) Open the Settings form and click the Configuration Files tab
b) Select the Template Files option
c) Find the GlobalSettings.xml file in file list then right-click and chose Activate Project-Specific Copy. This will place a copy or the file in your project user folder.
d) Close the Settings file
e) Choose Add Tasks from the Toolbar
f) Select Custom Scripts from the Source Type dropdown
g) Specify your project user folder in the Select Source Directory folder
h) Click Scan and Display Source Files
i) Add the GlboalSettings.xml file to your project
j) Click the Save and Close button

2) Edit your GlobalSettings file adding an EditFile command for the VBP.

  • In this case, I want to edit the VBP file and remove a record from the file.
  • set Source to the path to the VBP file.
  • set OldBlock to the content to match
  • have no NewBlock element in the XML

<GlobalImports>
<Storage Action="Create" Identifier="%UserFolder%\GlobalSettings" />
<Registry type="EditFile" Source="%VirtualRoot%\YourApp.vbp">
   <Fix name="EditFile">
   <Replace status="active" name="name">
   <OldBlock><![CDATA[Form=Form Modules\YourFile.frm]]></OldBlock>
   </Replace>
   </Fix>
</Registry>
<Storage Action="Close" />
</GlobalImports>


3) Translate the GlobalSettings.xml task using the Translate Operation.
This will create a GlobalSettings.vbi file


4) Add <Select GlobalSettings...> command to your translation script. Typlically place this the options section of the script before the Compile command:


<gmBasic>
<Storage Action="Create" Identifier="%JobId%" />
...
<!-- Translation options -->

<Select GlobalSettings="%UserFolder%\GlobalSettings" />
...
<Compile...>


5) Run the translation script that includes the <Select GlobalSettings ...> command. gmBasic will edit the VBP prior to compiling it.