Code:
Public Function update_from_logfile()
Dim appAccess As Access.Application
Set appAccess = CreateObject("Access.Application.9")
Dim stLogFileName As String
Dim intIdx, i As Integer
Dim stKeyword1, stKeyword2 As String
Dim logfile, filesys
Dim datetimeRec, h14Rec, h15Rec, h30Rec, h31Rec, valCRCRec As String
Dim logrec As String
' This function updates the checksum and CRC values from the VHLC program log files for the
' record currently displayed in the form.
' First initialize some variables to use for the search.
' Get the fully-qualified vital log file name from the form values.
stDirFileName = Trim(Directory_File_Name)
' The dir path name may or may not contain a trailing "\", so add it if it needs to be added.
If Right(Directory_File_Name, 1) <> "\" Then
stDirFileName = stDirFileName & "\"
End If
stLogFileName = stDirFileName & Vital_File_Name & ".log"
' Make sure the log file exists first.
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(stLogFileName) Then
Reset
' Open the file for input
Open stLogFileName For Input As 1
' Get the last H14, H15, Validation CRC and compile date/time entries in the file.
Do While Not EOF(1)
Line Input #1, logrec
If InStr(logrec, "compiled") > 0 Then
datetimeRec = logrec
Else
If InStr(logrec, "Checksum") > 0 Then
If InStr(logrec, "IC14") > 0 Then
h14Rec = logrec
Else
h15Rec = logrec
End If
Else
If InStr(logrec, "Validation CRC") > 0 Then
valCRCRec = logrec
End If
End If
End If
Loop
' Update the Vital compile date.
If Len(Trim(datetimeRec)) > 0 Then
Date_Vital_Created.SetFocus
Date_Vital_Created.Value = Mid(datetimeRec, (InStr(datetimeRec, "System compiled") + 16), 11)
End If
' Update the H14 CRC and Checksum.
If Len(Trim(h14Rec)) > 0 Then
Vital_CRC.SetFocus
Vital_CRC.Value = Mid(h14Rec, (InStr(h14Rec, "CRC") + 4), 4)
Vital_Checksum.SetFocus
Vital_Checksum.Value = Mid(h14Rec, (InStr(h14Rec, "Checksum") + 9), 4)
End If
' Update the H15 CRC and Checksum.
If Len(Trim(h15Rec)) > 0 Then
Vital_CRC_2.SetFocus
Vital_CRC_2.Value = Mid(h15Rec, (InStr(h15Rec, "CRC") + 4), 4)
Vital_Checksum_2.SetFocus
Vital_Checksum_2.Value = Mid(h15Rec, (InStr(h15Rec, "Checksum") + 9), 4)
Else
' If the H15 record does not exist, set the H15 values to blank.
Vital_CRC_2.SetFocus
Vital_CRC_2.Value = " "
Vital_Checksum_2.SetFocus
Vital_Checksum_2.Value = " "
End If
' Update the Validation CRC.
If Len(Trim(valCRCRec)) > 0 Then
Validation_CRC.SetFocus
Validation_CRC.Value = Mid(valCRCRec, (InStr(valCRCRec, "CRC") + 6), 8)
End If
' Close the file. We're done with the vitals.
Close 1
Else
MsgBox "Vital Log File " & stLogFileName & " not found."
End If
' Now get the NONVITAL log file values.
' Initialize the variables being reused.
datetimeRec = ""
' Format the nonvital log file name.
stLogFileName = stDirFileName & Non_Vital_File_Name & ".log"
' Check to see if the nonvital log file exists.
If filesys.FileExists(stLogFileName) Then
Reset
' Open the file for input
Open stLogFileName For Input As 1
' Get the last H14, H15, Validation CRC and compile date/time entries in the file.
Do While Not EOF(1)
Line Input #1, logrec
If InStr(logrec, "compiled") > 0 Then
datetimeRec = logrec
Else
If InStr(logrec, "Checksum") > 0 Then
If InStr(logrec, "IC14") > 0 Then
h30Rec = logrec
Else
h31Rec = logrec
End If
End If
End If
Loop
' Update the NonVital compile date.
If Len(Trim(datetimeRec)) > 0 Then
Date_Non_Vital_Creat.SetFocus
Date_Non_Vital_Creat.Value = Mid(datetimeRec, (InStr(datetimeRec, "System compiled") + 16), 11)
End If
' Update the H30 CRC and Checksum.
If Len(Trim(h30Rec)) > 0 Then
H30_U10_CRC.SetFocus
H30_U10_CRC.Value = Mid(h30Rec, (InStr(h30Rec, "CRC") + 4), 4)
Non_Vital_1st_Checks.SetFocus
Non_Vital_1st_Checks.Value = Mid(h30Rec, (InStr(h30Rec, "Checksum") + 9), 4)
End If
' Update the H31 CRC and Checksum.
If Len(Trim(h31Rec)) > 0 Then
H31_U9_CRC.SetFocus
H31_U9_CRC.Value = Mid(h31Rec, (InStr(h31Rec, "CRC") + 4), 4)
Non_Vital_2nd_Checks.SetFocus
Non_Vital_2nd_Checks.Value = Mid(h31Rec, (InStr(h31Rec, "Checksum") + 9), 4)
End If
' Close the file. We're done.
Close 1
Else
MsgBox "Nonvital Log File " & stLogFileName & " not found."
End If
End Function
I think this is it.