hexagon logo

Counting days since a program was run

This script keeps track of the number of workdays the CMM has been run, and displays a warning to run a calibration program when the file hits a certain number of days.

Sub Main()

Dim Templine as String
Dim TotalFileTxt as String
Dim OldDate as String

DATE = FORMAT(Date, "mm/dd/yyyy")

'Opens the .txt file to read the txt in there
handle = FreeFile
Open "C:\Datecheck.txt" For Input As #handle
Do While Not EOF(handle)
	Input #handle, Templine
	TotalFileTxt = TotalFileTxt + Templine  'totalfiletext contains everything in the .txt file after this do loop.
Loop
Close #handle

If Len(TotalFiletxt) > 70 Then   'Assuming date is in mm/dd/yyyy, 70 is seven days worth of date entries in the .txt file.
	Msgbox "It has been more than seven working days since the calibration program was last run! Run the calibration program"
	Goto SkipScript   'Skips everything else, does not put in new entry.
End If 

'Continues on if there are less than 7 days in the .txt file

'Scans through the text in the file to see if the current date is already in there
counter = 1
Do Until counter = Len(TotalFileTxt) + 1
OldDate = Mid(TotalFileTxt, counter, Len(DATE))
If OldDate = DATE Then
MsgBox "We have already written an entry for today! The script will skip the rest of the code"
Goto SkipScript         'skips putting in today's date if an entry is found
End If
counter = counter + 1
Loop

'The following outputs the current date to the txt file as a new line

handle = FreeFile
Open "C:\Datecheck.txt" For Append As #handle
  Print #handle, DATE
Close #handle

Skipscript:

End Sub



**Within the calibration program, put this line to reset the Datecheck file and start counting anew:
DELETE\"C:\Datecheck.txt"