' check production versus load and turn on/off a device ' Preferrably Disk E should be solid state or ramdisk Dim Load As String Dim Production As String Dim State As Boolean Const Hysteresis As Integer = 500 ' Margin to allow before change Dim FilesDate As String Dim MetersFilesTime As String Private Sub Form_Load() If Command$ = "" Then Exit Sub ' If no Load passed as a parameter - end process Load = Command$ CheckState Unload Me End Sub Sub CheckState() If FileExists("E:\Meters.txt") Then If FilesDate <> MetersFilesTime Then MetersFilesTime = FilesDate On Error Resume Next Open "E:\Meters.txt" For Input Shared As #1 Line Input #1, TimeStamp Line Input #1, Production Close #1 If Production < Val(Load) - Hysteresis Then TurnOff Else If Production > Val(Load) + Hysteresis Then TurnOn End If ' In between Hysteresis do nothing End If End If End Sub Sub TurnOn() If FileExists("E:\On") Then Exit Sub ' already on State = True If FileExists("E:\Off") Then Kill "E:\Off" Open "E:\On" For Output As #1 Close #1 Shell "TurnOn.bat" End Sub Sub TurnOff() If FileExists("E:\Off") Then Exit Sub ' already off State = False If FileExists("E:\On") Then Kill "E:\On" Open "E:\Off" For Output As #1 Close #1 Shell "TurnOff.bat" End Sub Function FileExists(folderspec) Dim fs, f, f1, fc, S On Error GoTo err FilesDate = "" FileExists = False Set fs = CreateObject("Scripting.FileSystemObject") Set file = fs.getfile(folderspec) FilesDate = file.datelastmodified FileExists = fs.FileExists(folderspec) Set file = Nothing Set fs = Nothing err: On Error GoTo 0 End Function