FormDocs Automation Basic Editor - Scripting Samples - Support

FormDocs Automation Basic Editor - Scripting Samples

From Support

Jump to: navigation, search

Contents

Utilizing the "FormDocs Automation Basic Editor" (AKA Forms Scripting)

Step 1: Open the Form Template

Launch the FormDocs Designer. Open the desired FormDocs Form Template or create a new form.

Step 2: Open the "FormDocs Automation Basic Editor"

Select Tools > Forms Automation Basic Editor from the menu bar. This will open up a new window:

The FormDocs Automation Basic Editor can be opened via the file menu:
 Tools > Forms Automation Basic Editor

or by using your keyboard:
 Alt + F11

Image:fdscripts1.png

NOTE: You can also open the Forms Automation Basic Editor using Alt + F11

Step 3: Locating the Scripts for the Current Form

In this new window, locate the drop-down menu labeled "Automate this Object:" in the upper- left region and select "Form" from the drop-down menu (2nd option).

Step 4: Locating the "BeforePrint" Event

Now locate the drop-down menu labeled "Program this event:" once again in the upper- right region and select BeforePrint from the drop-down menu.

Step 5: Where to Write the Script

In the main window (no label), you will need to write your script after the line starting with "Private Sub...." and before the line that reads "End Sub".

Image:fdscripts2.png


Scripting Within Your Form

FormDocs scripting uses syntax from Visual Basic. If you look at the image above, you will see references to the different functions that you can use from Visual Basic. This can be located in the bottom left corner and is labeled "View Language Reference." The drop-down covers different categories of functions.

The scrolling window directly below the drop-down lists the available functions in that category. If you highlight a function in the list, the center section directly to the right will display information about that function and its syntax. If you double-click on the function, the function name will be pasted into your script at the cursor location.

If you are unfamiliar with Visual Basic, you should know that Visual Basic uses a programming standard called Object-Oriented Programming.

You can look at a listing of objects that your form has available. This is located in the bottom right corner and is labeled "View Object Model Reference." The drop-down lists the different objects that you are allowed to reference directly in your script. Above the divider within the dropdown are the actual objects. Below the line are some constants.

The scrolling window directly below the drop-down lists the available functions for each object. If you highlight a function in the list, the center section directly to the left will display information about that function and its syntax. If you double-click on the function, the function name will be pasted into your script at the cursor location.

Scripting 101

When you are referencing an object in your script, you will need to do so by first referencing your form object and then selecting "child" objects from there.

For example: If I want to assign the string "This is only a test." to the field "TEST", I must first reference the form, then the field (among a list of all the fields) and finally I would reference the value of the field. The script for this would be as follows:

ThisForm.Fields("TEST").Value = "This is only a test."

A comment is created simply placing a single quote before your comment. A comment will continue until the end of the line. Comments can be used to hide or "comment out" part of a script that you do not wish to use, but do not feel like deleting as there could be later use for it. It is often used when adding extra code for testing and debugging your script.

For example:

'Assigning our string to the TEST field.
ThisForm.Fields("TEST").Value = "This is only a test."

Scripting Samples

Included are a few basic scripting examples. Please contact Technical Support for further samples or for simple questions on your scripting.

Need help scripting your forms? Let us write the script for you! Contact Technical Support to get a quote!

Example 1: Page Turning

Page Turning - NOTE: This is ideal for forms that contain Terms & Conditions or forms where the last page varies slightly from the previous pages.

'////////////////////////////////////////////////////
 ' Setup conditions for turning on pages using a
 ' simple IF-ELSE condition statement.
 '
 ' NOTE: Form names and page names will vary for each
 ' form developer.  Please ensure that you change the
 ' script to match those names...
 '////////////////////////////////////////////////////
If trim(ThisForm.Fields("TriggerField").Value) = "My Trigger Value" Then
	
	'Enable Page 1 and Disable Page 2
	ThisForm.Pages("FormPage_1").Printable = true
	ThisForm.Pages("FormPage_2").Printable = false

Else

	'Disable Page 1 and Enable Page 2
	ThisForm.Pages("FormPage_1").Printable = false
	ThisForm.Pages("FormPage_2").Printable = true

End If

Example 2: Copying Fields From One Page to Another

Assigning Fields from one page to another - NOTE: This typically works best with page turning. You have two nearly identical pages except for a few stray fields and do not want to keep re-mapping the fields in the Text Layer Designer.

 '////////////////////////////////////////////////////
 ' This script will copy the value from each field
 ' on a page to a corresonding field on a different
 ' page in the same form.
 '////////////////////////////////////////////////////
 
 '////////////////////////////////////////////////////
 ' I am forced to assume that you are using logical
 ' names for each field on each page.  For example if
 ' a field is named "Test" on page one it would be
 ' named "Test_2" on page 2, "Test_3" on page 3 and so
 ' on and so forth.  Fields that are unique to specific
 ' pages must still be mapped...
 '////////////////////////////////////////////////////
       
' Declare a Field object - this will be a working variable
Dim lcField As Field

' loop through each field on page one and copy the value to the same field on page 2
For Each lcField In ThisForm.Pages("FormPage_1").Fields

	'Make sure that there is not already a value in that field...
	If ThisForm.Fields(lcField.name + "_2").value = "" Then
		
		' This is VERY important.  If a field exists on page 1 and not on page 2,
		' the merge will fail unless this next line is here.
		On Error Resume Next

		' This next line may not be needed, if you are scripting
		' logo images or barcode images, you must activate the field first.
		ThisForm.Fields(lcField.name + "_2").activate

		' Assign the value
		ThisForm.Fields(lcField.name + "_2").value = ThisForm.Fields(lcField.name).value
	' End If Statement
	End If
' Get next Field and repeat the loop...
Next


Example 3: Specifying a Print Tray For One Page of the Form

Setting a page to print on a specific printer tray is as easy as 1, 2, 3.


1. Find the Printer Tray number for your printer

Since Print Tray Numbers are not always consistant from printer to printer (and occasionally from print driver to print driver), it is recommended that you download the following Utility to help you identify the Print Tray Number for your printer.

Download the RJS Print Tray Utility

2. Assign/Verify the name of your Form Page

In FormDocs, select Page > Page Properties from the menu bar. The "General" tab will contain your current page name. If you have not done so, enter a name for your page that you can remember.

NOTE: Each page has its own unique name.


3. Adding Printer Tray Code to your Script

Open the Scripting Editor and add code similar to the code below for each page that you want to send to a different print tray.

ThisForm.Pages("page name").PrintPaperTray = TrayNumber



This article has been proofread by Nick as of 10:28, 12 December 2006 (Central Standard Time)
Personal tools