Script

QWAdmin Help Files

Quality Window offers many hook-points within its update function for user-defined functionality.

 

These hook-points can be divided into two types:

 

Batch File Executions

Scripting User Exits

 

The following table outlines the execution flow:

Run Batch File when Add key pressed        

 

Executes the batch file defined in the template.  Typically, this is where one would collect outside information and save it to Input Files for later display within the Add screen.

QW_Initialize    (User Exit)        

 

This is the Scripting alternative to running the above batch file, however there is no need to use Input Files because the Script code can load the values directly into the Add screen.

Input Files are read        

 

All Input Files are read and replace values on the Add screen.

QW_BeforeDisplay    (User Exit)        

This scripting exit allows you to manipulate the values on the Add screen just prior to it being displayed.  Note that you have access to whatever data was read in from the input files.

Display Input Form        

At this point, the Add screen is displayed with current values until either Save or Cancel is pressed.

QW_AfterDisplay    (User Exit)        

This scripting exit allows you to manipulate the data just prior to it being committed to disk.  Note that validation has already been performed prior to this exit so it is up to you to make sure that any new values are valid.

Recalculate Record(s) and Write Updated Record(s)        

The current record (and any others it may affect) are recalculated and committed to disk.

Write Output Files        

All Output Files are written to disk

Write Transaction Log        

If specified, a transaction record is written for each changed record.

QW_DuringUpdate    (User Exit)        

This scripting exit can be called multiple times depending on moving calculated fields.  Upon each call, the current record being updated is passed.

QW_AfterUpdate    (User Exit)        

This scripting exit occurs after all data has been committed and the Add screen is about to close.

Run Batch File after Save pressed        

Executes the batch file after Save pressed (if specified)

 

 

Batch Files

Batch files are implemented identically to QW 4.5 where one or more commands may be entered into the batch file to be executed.

 

The format of the Batch file is as follows:

 

BatchFilename  ApplName  Function

 

QW will append the Application Name and the Function when executing the batch file.  Function can be one of the following:

 

A, E, I, C, D  depending on the function (Add, Edit, Insert, Copy, Delete)

 

 

Scripting

 

Quality Window 5.0 introduces a new level of interaction using Microsoft’s Scripting Host technology.  During the update phase, critical points can now be coded to perform specific functions.  QW50 supports both VBScript and JavaScript.  The script exits are all contained within a single file named: application.qwx (it is not necessary to include/handle all of the exits  only those that you wish to perform some function).

 

When any exit is fired, it receives the current function being performed as a parameter:

 

A        Add Record

D        Delete Record

E        Edit Record

I         Insert Record

C        Copy Record

 

The function can optionally return a value back to the scripting host.  

 

Valid values that can be returned are:

 

  • CANCEL which prevents any other exits from firing and immediately exits the Update screen.
  • SAVE which can be used in the first two exits to effectively skip the display stage and go directly to saving the record.

 

 

 

The following is a Vbscript example of the basic structure of the scripting exits:

 

Option Explicit

 

Function QW_Initialize(QWFunction)

        Select Case QWFunction

                Case "A" 'Add Record

                Case "D" 'Delete Record

                Case "E" 'Edit Record

                Case "I" 'Insert Record

                Case "C" 'Copy Record

        End Select

End function

 

Function QW_BeforeDisplay(QWFunction)

        Select Case QWFunction

                Case "A" 'Add Record

                Case "D" 'Delete Record

                Case "E" 'Edit Record

                Case "I" 'Insert Record

                Case "C" 'Copy Record

        End Select

End Function

'================================================

 

Function QW_AfterDisplay(QWFunction)

        Select Case QWFunction

                Case "A" 'Add Record

                Case "D" 'Delete Record

                Case "E" 'Edit Record

                Case "I" 'Insert Record

                Case "C" 'Copy Record

        End Select

End Function

 

Function QW_DuringUpdate(QWFunction)

        Select Case QWFunction

                Case "A" 'Add Record

                Case "D" 'Delete Record

                Case "E" 'Edit Record

                Case "I" 'Insert Record

                Case "C" 'Copy Record

        End Select

End Function

 

Function QW_AfterUpdate(QWFunction)

 

Select Case QWFunction

                Case "A" 'Add Record

                Case "D" 'Delete Record

                Case "E" 'Edit Record

                Case "I" 'Insert Record

                Case "C" 'Copy Record

        End Select

End Function

 

The following is the same script but using JavaScript instead:

(Note that the first line is required to tell the Scripting Host what scripting language to use)

 

// Language=JSCRIPT

 

function QW_Initialize(QWFunction) 

{

}

 

function QW_BeforeDisplay(QWFunction) 

{

}

 

function QW_AfterDisplay(QWFunction) 

{

}

 

function QW_DuringUpdate(QWFunction) 

{

}

 

function QW_AfterUpdate(QWFunction) 

{

}

 

 

 

A Countdown Timer Example

 

This script will display a Countdown Timer until the user presses the Ok button, at which time the elapsed seconds are converted to minutes and placed into the Minutes_Down variable (V9).  Note that if the Cancel button is pressed, then the script returns ‘CANCEL’ and the Add screen is bypassed and QW returns to the Log Sheet.

 

Function QW_BeforeDisplay(QWFunction)

        Select Case QWFunction

                Case "A" 'Add Record

                        Dim QWtimer

                        Set QWtimer = CreateObject("QWtool.Timer")

                        QWtimer.HeaderTitle = "Elapsed Time"

                        QWtimer.FooterTitle = "Downtime Cost"

                        QWtimer.FooterBaseValue = 80.00

                        QWtimer.FooterMultiplier = 0.42

                        QWtimer.FooterFormat = "$##,##0.00"

                        QWtimer.Display

                        If QWtimer.Cancel = False Then

                           QWfile.Value(9) = QWtimer.ElapsedSeconds / 60

 

Else

                           QW_BeforeDisplay = "CANCEL"

                        End If

        End Select

End Function

 

 

Update Microsoft Access Database Example

 

The following is a sample script which will synchronize an Access database to the current QW database.  All changes made to the file through the Update screen will be reflected in the Access database including Edits and Inserts where multiple records may be updated due to calculated fields using moving functions.  This script depends on the AutoNumber being used within the QW application and that the field name of the AutoNumber field in the access database be called ID, as well as that all QW fields exist in the Access database in the same order with similar field types.  This script also assumes the Access database name to be the same as the QW application name, with the .mdb extension.  It also assumes the Access Table name to be ‘DBSYNC’, which of course, can all be changed.

 

Option Explicit

 

Dim oConnection, oRecordset

 

Function QW_AfterDisplay(QWFunction)

        Dim dbName

        Set oConnection = CreateObject("ADODB.Connection")    

        dbName = QwFile.FileName & ".mdb"

        oConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbName & ";"

        oConnection.Open

End Function

 

Function QW_DuringUpdate(QWFunction)

        Dim i, TableName

        TableName = "DBSync"

        Set oRecordSet = CreateObject("ADODB.RecordSet")     

        oRecordSet.Open TableName, oConnection, 1, 3, 2

        Select Case QWFunction

 

Case "A", "I", "C", "E" 'Add Insert, Copy Record

                        oRecordset.Find "ID = " & QwFile.Value(QwFile.AutoNumber)

                        If oRecordset.EOF Then oRecordset.AddNew

                        For i = 1 to QwFile.Fields.Count

                                oRecordset.Fields(i-1).Value = QwFile.Value(i)

                        Next

                        oRecordset.Update

                Case "D" 'Delete Record

                        oRecordset.Find "ID = " & QwFile.Value(QwFile.AutoNumber)

                        If Not oRecordset.EOF Then oRecordset.Delete

        End Select   

        oRecordset.Close

 

Set oRecordset = Nothing

End Function

 

Function QW_AfterUpdate(QWFunction)

        If oConnection.State = 1 Then oConnection.Close

        Set oConnection = Nothing

End Function

 


Script Menu

Click Script / Append Default Script to paste a default skelton script for this template.