Thursday, April 1, 2021

Change the programming language of a form template

A form template can only contain script or managed code that is written in one programming language. You can change the programming language of a form template by removing the original script or managed code, specifying a new programming language, rewriting the original script or managed code in the new programming language, and then adding the new script or managed code to the form template.

Note: InfoPath cannot convert existing script or managed code from one programming language to another programming language.

In this article

Overview

When you need to use script or managed code to add business logic to your form template, such as performing a complex calculation by using values that users enter into forms based on your form template, you can add your business logic by using one of several different programming languages, including C# or Microsoft Visual Basic. After you add script or managed code to your form template, any changes that you want to make, or any new script or managed code that you want to add to your form template must be written in the same programming language.

As your form template evolves to meet new business requirements, you may need to change the programming language used in your form template. For example, imagine the following situations:

  • Your company has a new policy that all Microsoft Windows programs and program extensions developed by your department use the C# programming language. The existing form templates used in your company were designed using the Visual Basic programming language. To comply with the new policy, you must convert all of the form templates so that they use the C# programming language.

  • You published a form template created in Microsoft Office InfoPath 2003 that has script written in JScript. Because Microsoft Office InfoPath 2007 allows your users to fill out forms based on a form template in a Web browser, you must convert this form template into a browser-enabled form template, and then publish it to a server running InfoPath Forms Services. However, InfoPath Forms Services can only display form templates with managed code assemblies; you cannot publish a form template that contains script to a server running InfoPath Forms Services. You must convert the script into a managed code assembly so that you can publish the form template to a server running InfoPath Forms Services.

  • You are responsible for maintaining several form templates that you did not design. These form templates contain scripts written in JScript. Although you can read and write scripts written in JScript, you are much more proficient at writing scripts using the Microsoft Visual Basic Scripting Edition (VBScript) programming language. Because you will be maintaining these form templates, it will be much more efficient if the script was written in VBScript, so you decide to replace the existing scripts written in JScript with scripts written by using VBScript.

If you need to change the programming language used in an existing form template, you must first remove the existing script or managed code from the form template, and then you specify the new programming language for the form template. Once you change the programming language in the form template, you can rewrite the script or managed code in the new language, using the Microsoft Script Editor or Microsoft Visual Studio Tools for Applications, and then you add the new script to your form template.

Top of Page

Change the programming language of a form template

Before you change the programming language of a form template, you may want to save a copy of the original source code in a text editor, such as Microsoft Notepad, in case you need to refer to it or use the original code.

Save the original source code

  1. Open your form template in design mode.

  2. On the Tools menu, point to Programming, and then do one of the following:

    • If your form template contains script, click Microsoft Script Editor.

    • If your form template contains managed code, click Microsoft Visual Studio Tools for Applications.

  3. On the Edit menu of the Microsoft Script Editor or Microsoft Visual Studio Tools for Applications, click Select All.

  4. On the Edit menu, click Copy.

  5. Paste the code you copied to a text editor, such as Notepad.

  6. Save the text editor file.

Change the programming language of the form template

  1. On the Tools menu, click Form Options.

  2. Under Category in the Form Options dialog box, click Programming.

  3. Under Programming language, click Remove Code.

  4. Click Yes in the message box warning you that you are about to remove the code from the form template.

  5. In the Form template code language list, click the language that you want to use in the form template.

    Tip: If you are changing the programming language to Visual Basic or C#, in the Project location for Visual Basic and C# code box, type the location where you want to save the project files.

Top of Page

No comments:

Post a Comment