0% found this document useful (0 votes)
192 views9 pages

QWupdate

QWUPDATE offers many hook-points within its update function for user-defined functionality. The following table outlines the execution flow for batch file executions and scripting user exits. Batch files are implemented identically to QW 4 where one or more commands may be entered into the batch file to be executed.

Uploaded by

kgskgm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views9 pages

QWupdate

QWUPDATE offers many hook-points within its update function for user-defined functionality. The following table outlines the execution flow for batch file executions and scripting user exits. Batch files are implemented identically to QW 4 where one or more commands may be entered into the batch file to be executed.

Uploaded by

kgskgm
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

QWUPDATE Documentation

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 and Scripting User Exits The following table outlines the execution flow: Run Batch File when Add key pressed QW_Initialize (User Exit) 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. 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. All Input Files are read and replace values on the Add screen. 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. At this point, the Add screen is displayed with current values until either Save or Cancel is pressed. 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. The current record (and any others it may affect) are recalculated and committed to disk. All Output Files are written to disk If specified, a transaction record is written for each changed record. This scripting exit can be called multiple times depending on moving calculated fields. Upon each call, the current record being updated is passed. This scripting exit occurs after all data has been committed and the Add screen is about to close. Executes the batch file after Save pressed (if specified)

Input Files are read QW_BeforeDisplay (User Exit)

Display Input Form QW_AfterDisplay (User Exit)

Recalculate Record(s) and Write Updated Record(s) Write Output Files Write Transaction Log QW_DuringUpdate QW_AfterUpdate (User Exit) (User Exit)

Run Batch File after Save pressed

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) Scripts: Quality Window 5.0 introduces a new level of interaction using Microsofts 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).

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) { } 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. REDO which can be used in AfterDisplay to warn the user of a validation error and return back to the Edit screen.

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 This next script will on Add, Insert and Copy, initialize Field 14 of the current application with Field 24 of the last record in the application monitor. Notice how you have to create a new object for a second QWaccess to access another application: Function QW_BeforeDisplay(QWFunction) Dim QWfile2 Select Case QWFunction Case "A", C, I Set QWfile2 = CreateObject("QWaccessClass.QWaccess") QWfile2.OpenFile "c:\busitech\qw50\samples\monitor" QWfile2.SeekLast QWfile2.GetPrev QWfile.Value(14) = QWfile2.Value(24) QWfile2.CloseFile End Select End Function

This next script will upon adding a new record to Monitor.qwt, add the identical record to Monitor2.qwt The new record in Monitor2 is also recalculated in case there are Calculated fields. Function QW_AfterUpdate(QWFunction) Select Case QWFunction Case "A" 'Add Record AddRecordToMonitor2 Case "D" 'Delete Record Case "E" 'Edit Record Case "I" 'Insert Record Case "C" 'Copy Record End Select End Function Sub AddRecordToMonitor2() Dim QWfile2, I, Rec Set QWfile2 = CreateObject("QWaccessClass.QWaccess") QWfile2.OpenMode = 2 'Update Mode QWfile2.OpenFile QWfile.FilePath & "\Monitor2.qwt" QWfile2.InitRecord For I = 1 To QWfile.Fields.Count QWfile2.Value(I) = QWfile.Value(I) Next I QWfile2.PutRecord 0 Rec = QWfile2.RecordNo QWfile2.ReCalcRecord Rec QWfile2.PutRecord Rec QWfile2.CloseFile End Sub

The following script will check the current value of variable 5. If the value is greater than 100, it will display a message to the operator and then return to the Edit screen. Function QW_AfterDisplay(QWFunction) If Not IsNull(Qwfile.Value(5)) Then If Qwfile.Value(5) > 100 Then MsgBox Value is too high! QW_AfterDisplay = REDO End If End If End Function

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

Within the same qwx file (or c:\Windows\System32\Qwscript.qwx) various Macros can be defined by simply adding new procedures beginning with MENU_ These macros will then be available on the QW50 menu bar under Macros. For example, the following macro would display a report of historical rule violations in the current template: Sub MENU_DisplayRuleViolations() Dim QWform, Rec, Row, I, Rule, ColPtr(), ColCount Set QWform = CreateObject("QWtool.Form") QWform.Caption = "Historical Rule Violations" ReDim ColPtr(QWrep.Fields.Count) ColCount = 2 ColPtr(1) = 1: ColPtr(2) = 2 For I = 3 To QWrep.Fields.Count If QWrep.Fields(I).FieldType = 4 OR _ QWrep.Fields(I).FieldType = 5 OR _ QWrep.Fields(I).FieldType = 6 OR _ QWrep.Fields(I).FieldType = 7 Then ColCount = ColCount + 1 ColPtr(ColCount) = I End If Next QWform.Grid.Rows = 1: QWform.Grid.Cols = ColCount For I = 1 To ColCount QWform.Grid.TextMatrix(0,I-1) = QWrep.Fields(ColPtr(I)).FieldName Next For Rec = QWrep.TibSelections(2).StartIndex To QWrep.TibSelections(2).EndIndex QWrep.TibSelections(2).EndIndex = Rec QWform.Grid.Rows = QWform.Grid.Rows + 1 Row = QWform.Grid.Rows - 1 QWform.Grid.TextMatrix(Row,0) = QWrep.GetFormattedData(Rec,1) QWform.Grid.TextMatrix(Row,1) = QWrep.GetFormattedData(Rec,2) For I = 3 To ColCount Set Rule = QWrep.CalculateRule(ColPtr(I),2,False) If Not Rule Is Nothing Then QWform.Grid.TextMatrix(Row,I-1) = Rule.Name End If Next Next QWform.Grid.AutoSize 0,QWform.Grid.Cols-1 QWform.Display End Sub The following very simple script will display some basic properties about the current template loaded: Sub MENU_DisplayProperties() Dim Properties Properties = Properties & Filename: & Qwfile.Filename & vbcrlf Properties = Properties & Fields: & Qwfile.Fields.Count & vbcrlf Properties = Properties & Records: & Qwfile.RecordCount MsgBox Properties End Sub

A companion program called QWADD.EXE also has scripting built in. QWAdd essentially loads a specified template, reads all Input files, recalculates a new record, writes the record, then exits. In the process, it also looks for special hookpoints into the templates qwx script file (or c:\Windows\System32\Qwscript.qwx). QWADD_Initialize Input Files are read QWADD_BeforeUpdate This scripting exit occurs just after opening the template and initializing the new record with Date/Time All Input Files are read and replace values within the new record. This scripting exit allows you to manipulate the values in the current record just prior to it being commited. Note that you have access to whatever data was read in from the input files. The current record is recalculated and committed to disk. This scripting exit occurs just prior to writing output files and transaction log. All Output Files are written to disk If specified, a transaction record is written. This scripting exit occurs after all data has been committed but prior to the template being closed.

Recalculate Record(s) and Write Updated Record(s) QWADD_DuringUpdate Write Output Files Write Transaction Log QWADD_AfterUpdate

The following is a VBscript example of the basic structure of the QWAdd scripting exits: Option Explicit Function QWADD_Initialize(QWfunction) End Function Function QWADD_BeforeUpdate(QWfunction) End Function Function QWADD_DuringUpdate(QWfunction) End Function Function QWADD_AfterUpdate(QWfunction) End Function

The following script will read the value of Variable 3 (possibly from an Input file) and do a Lookup to return a corresponding value from the lookup file then place the result in Variable 4. It also adds 1 to Variable 5 and stores the result in Variable 6. Function QWADD_BeforeUpdate(QWfunction) Dim Misc Set Misc = CreateObject(QWtool.Misc) QWfile.Value(4) = Misc.NumLookup("e:\projects\qwtool\test.txt", QWfile.Value(3)) QWfile.Value(6) = QWfile.Value(5) + 1 End Function Here is the Lookup file (Test.txt) used in the example above: 1,One 2,Two 3>5,Three to Five 6|7|8,Six or Seven or Eight 9,Nine ELSE,Something Else Note that QWAdd.exe requires a parameter for the application template to be acted upon. On the command line, you can also send optional parameters which can then be read from the script: QWAdd.exe c:\Busitech\QW50\Samples\Monitor.qwt,One,Two,Three In the script, Parms.Count would equal 3 and Parms(2).Value would equal Two

You might also like