There are certain tasks that you will want to perform at a specified time or interval or when a change occurs in the process. To schedule these tasks you will need to define the time that triggers the action that you want to occur. You can use the Scheduler application within iFIX or you can write your own VBA script. For more information on the Scheduler, refer to the Scheduler section of the Mastering iFIX manual.
The following example periodically checks the amount of available hard disk space. If the amount of disk space gets too low, it triggers an alarm in the iFIX database. The OnTimeOut event occurs at an interval defined in the properties of the CheckDiskSpace event.
Example: Checking Disk Space and Triggering an Alarm if Too Low
'First, declare the Windows API function call
'GetDiskFreeSpace so you can use it to get the amount of
'free space available on the disk.
Private Declare Function GetDiskFreeSpace Lib "kernel32" _
Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters _
As Long) As Long
'Check the disk space on the Timer Event's OnTimeOut
'event. If it is less than 150MB, set an alarm.
'CheckDiskSpace is the name of the Timer object
'created in the Scheduler.
Private Sub CheckDiskSpace_OnTimeOut(ByVal lTimerId As Long)
Dim lAnswer As Long
Dim lpRootPathName As String
Dim lpSectorsPerCluster As Long
Dim lpBytesPerSector As Long
Dim lpNumberOfFreeClusters As Long
Dim lpTotalNumberOfClusters As Long
Dim lBytesPerCluster As Long
Dim lNumFreeBytes As Double
Dim lDiskSpace As Double
'Warning: The parameter below hard codes C: as the drive to
'check. If you do not nave a C: drive, this code will return 0
'as the free space. You need to change this parameter to match
'the drive you want checked.
lpRootPathName = "c:\"
lAnswer = GetDiskFreeSpace(lpRootPathName, _
lpSectorsPerCluster, lpBytesPerSector, _
lpNumberOfFreeClusters, lpTotalNumberOfClusters)
lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector
lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters
lDiskSpace = Format(((lNumFreeBytes / 1024) / 1024), _
"0.00")
If lDiskSpace < 150# Then
Fix32.NODE1.lowdiskspacealarm.f_cv = 1
Else
Fix32.NODE1.lowdiskspacealarm.f_cv = 0
End If
End Sub