Using Scripts with Event-based Entries

The following is an example of downtime monitoring. The Scheduler application waits for the value of FIX32.NODE1.DOWNTIMESTART.F_CV to be true. When it is true, the script launches a form that allows the user to enter the reason for the downtime occurrence. When the user clicks OK, the script opens the appropriate database and writes the time, date, data source, and downtime description to the database. Use the parameters in the following table to create the event object and the form. Be careful to place the Option Buttons inside the Frame.

DownTime Start Event Properties 

OBJECT

PROPERTY

SETTING

Event

Name
Event Type
Data Source

Line1Packer1DownTime
On True
Fix32.NodeName.DownTimeStart.F_CV

Form

Name
Caption

frmDownTime
Downtime Monitoring Logging to Relational Database

Command Button

Name
Caption

cmdOK
OK

Frame

Name
Caption

fraLine1Packer1
Packaging Line 1 Packer 1

Option Button

Name
Caption

optDownTimeReasonOne
Bad packaging material

Option Button

Name
Caption

optDownTimeReasonTwo
Fallen bottle or bottle jam on line to packer

Option Button

Name
Caption

optDownTimeReasonThree
Low oil pressure in packer drive

Option Button

Name
Caption

optDownTimeReasonFour
<Leave this caption blank>

Textbox

Name
Enabled

TxtDownTimeReasonFour
False

Example: Recording DownTime Monitoring

'Place the following code into the subroutine created after

'clicking the VB Editor button in the Modify Event Entry dialog.

 

'On the Event object's OnTrue event, initialize the form

'with the Event's data source and then show the form.

'Line1Packer1DownTime is the name of the event created

'in Scheduler.

 

Private Sub Line1Packer1DownTime_OnTrue()

     frmDownTime.InitializeDataSource _

     (Line1Packer1DownTime.Source)

     frmDownTime.Show

 

End Sub

 

Downtime Monitoring Logging to the Relational Database

'Place the following code directly in the form you create and 'set a reference to Microsoft DAO 3.X Object Library. See 'Visual Basic Editor Help for details on setting references.

 

Public sDataSource As String

 

'This is the initialize routine that is called from the Event

'object's OnTrue event. It creates a public instance of the

'string name of the data source for the form to use.

Public Sub InitializeDataSource(DataSource As String)

     sDataSource = DataSource

 

End Sub

 

'When the option button beside the text box is selected,

'enable and set focus to the text box.

Private Sub optDownTimeReasonFour_Click()

 

     txtDownTimeReasonFour.Enabled = True

     txtDownTimeReasonFour.SetFocus

 

End Sub

 

'When the form gets activated, set the first option to true

Private Sub UserForm_Activate()

     optDownTimeReasonOne.Value = True

 

End Sub

 

'When the user selects OK, store which reason they chose.

Private Sub cmdOK_Click()

     Dim DownTimeReason As String

     If optDownTimeReasonOne.Value = True Then

          DownTimeReason = optDownTimeReasonOne.Caption

     ElseIf optDownTimeReasonTwo.Value = True Then

          DownTimeReason = optDownTimeReasonTwo.Caption

     ElseIf optDownTimeReasonThree.Value = True Then

          DownTimeReason = optDownTimeReasonThree.Caption

     ElseIf optDownTimeReasonFour.Value = True Then

          If txtDownTimeReasonFour.Text <> "" Then

               DownTimeReason = txtDownTimeReasonFour.Text

          Else

               MsgBox "Please enter a reason for the _

               downtime event"

               txtDownTimeReasonFour.SetFocus

          End If

     End If

 

'Call the AddDownTimeEventData subroutine to add the

'downtime information to the database.

Call AddDownTImeEventData(DownTimeReason)

     Unload Me

 

End Sub

 

'This subroutine writes the data to the database and

'updates it.

'This database has not been provided and will need to be created

'for this subroutine to execute without error.

 

Public Sub AddDownTImeEventData(DownTimeReason As String)

 

     'Create an instance of the Workspace.

     Dim wrkSpace As Workspace

     Set wrkSpace = CreateWorkspace("", "admin", "", dbUseJet)

 

     'Open the downtime database.

     Dim db As Database

     Set db = wrkSpace.OpenDatabase(System.PicturePath & _

     "\downtime.mdb")

 

     'Create a recordset.

     Dim rs As Recordset

     Set rs = db.OpenRecordset("Packaging", dbOpenDynaset)

 

     'Set up the time of downtime occurrence.

     Dim TimeDate As Date

     TimeDate = Now

     rs.AddNew

     rs.Fields(1) = TimeDate

     rs.Fields(2) = TimeDate

     rs.Fields(3) = sDataSource

     rs.Fields(4) = DownTimeReason

     rs.Fields(5) = Fix32.NODE1.downtimeperiod.f_cv

     rs.Update

 

End Sub

 

See Also