Writing the script code
As explained in the previous section, the scripting functionality in
Canvas is organized in a hierarchy that reflects the structure of Can-
vas itself (see Scripting hierarchy, page 38.745). The Applica-
tion object is at the top of the hierarchy. Scripts have to create a
Canvas Application object in order to to access other parts of the
hierarchy. In the Downsample script, you create the Canvas
Application object when the script is started. First, define the
global variable cvApp as Canvas.Application. In the proce-
dure Form_Load, you then create a new Canvas Application
object and assign it to cvApp.
Dim cvApp As Canvas.Application
...
Private Sub Form_Load()
Set cvApp = New Canvas.Application
End Sub
Creating a Canvas Application object starts Canvas 8 in the
background. In other words, the user interface will not be visible.
Canvas is automatically shut down when the Application object
reference in the script becomes invalid. In the Downsample script,
the variable is globally accessible so it is valid until the script quits or
Nothing is assigned to it. Next, you set cvApp to Nothing in the
Form_Unload procedure, which is executed when a script quits. It
is good practice to assign Nothing to Application object refer-
ences. This ensures proper shutdown of the application when the ref-
erences become obsolete.
Private Sub Form_Unload(Cancel As Integer)
Set cvApp = Nothing
End Sub
Most operations of the Downsample script happen in the
SampleBtn_Click procedure, which is executed when the
Downsample button is pressed. First, set the mouse pointer to look
like an hourglass. This will signal to the user that the script is busy.
At the end of the procedure when the downsampling process is fin-
ished, the mouse pointer is reset to its default look.
Screen.MousePointer = vbHourglass
...