Skip to main content
Skip table of contents

Scriptlets

Scriptlets are snippets of code that are stored in the database for use in reports. One of the primary motivations for using scriptlets is to reduce the need to rewrite the same macro code in multiple reports. Having the macros in one location simplifies the process of making fixes to the code or adding functionality. In addition, a scriptlet can hide the details of the script from the report writer making the report writing process easier.

Scriptlets are created using the ActiveX Script Editor program that ships with CDD. The ActiveX Script Editor really only provides a mechanism to edit the scripts and it is necessary to perform most testing while running the reports. Once a scriptlet has been entered into the editor, you may check the syntax by choosing Compile from the Script menu. When the scriptlet is complete, choose Save from the File menu to insert it into the database.

To access a scriptlet from the macros of a report, select View > Report Properties > Script Reference tab from the main menu. Check the box next to desired scriptlet and click OK. The scriptlet can now be selected from the References drop-down in the Macros window. The Scriptlet cannot be edited from CDD; it can only be viewed.

CreateScriptObject

To call the methods in a scriptlet, it is necessary to first create an instance of the scriptlet using the CreateScriptObject function.

CreateScriptObject is used in the following manner:

Dim myScriptlet
Set myScriptlet = CreateScriptObject("MyScriptlet")

It is necessary to first declare the variable that will hold the reference to the Scriptlet as done above. In addition, be sure to note the use of "Set" to assign the object reference to the variable myScriptet.

Assume that MyScriptlet is defined as follows:

Option Explicit
Dim g_nErrorCode
Function CalcUserPay(nHours, nRate)
'Do something interesting here
CalcUserPay = 2300.00
End Function

Once the Scriptlet reference is returned by the call to CreateScriptObject, you could access the member functions and variables:

Dim nPay
nPay = myScriptlet.CalcUserPay(HOURS, RATE)
if nPay < 0 then
MsgBox "Error value " & myScriptlet.g_nErrorCode
endif

Scriptlet references are destroyed when one of three events occur:

  • The report ends,
  • The variable holding the reference goes out of scope,
  • The variable holding the reference is set to Nothing.

 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.