Attribute VB_Name = "A_Main"
Option Explicit
' -------------------------------------------------------------------------------------------------------------------------------------
' Software for filtering or renaming certain datasheet files for the Dataforth website. "Encoded" datasheet file names of a certain
' format are renamed, while datasheet file names that are invalid for the website are "filtered" by moving them out of the directory
' that is used for datasheets for the website. An external file is used to store the directory names of the main datasheet directory
' and the "filtered" datasheet files directory. The "filtered" files are moved to the "filtered" directory, rather than simply
' deleted, since they are sometimes used for test system debug or qualification.
' -------------------------------------------------------------------------------------------------------------------------------------
'
' The following constant sets the name of the program version that it printed out in the data (CSV file) test report file.
Public Const PROGRAM_NAME = "DFWDS"
Public Const PROGRAM_DESCRIP = "Dataforth Website Datasheet Program"
Public Const PROGRAM_VERSION = "DFWDS_2014_09_26"

' -------------------------------------------------------------------------------------------------------------------------------------
' AUTHORS:          Paul Reese
' DATE:             2014/09/24
' EXECUTABLE:       DFWDS.exe               = Executable program file.
' CODE PROJECT:     DFWDS.vbp               = Visual Basic project file.
' CODE MODULES:     DFWDS.bas               = this file, main code module.
' VB FORMS:         frmDBselect.frm         = form to select directory and .DAT file for model database.
'                   frmDATAselect.frm       = form to select .DAT file for stored model datasheet data and print
'                                             text file datasheets.
' -------------------------------------------------------------------------------------------------------------------------------------
'
' -------------------------------------------------------------------------------------------------------------------------------------
'       REVISION RECORD
'
'  DATE         APPR    DESCRIPTION
'  ----         ----    -----------
' 2014/09/24    PWR     Initial version.
'
' -------------------------------------------------------------------------------------------------------------------------------------

'----------------------------------------------------------------------------------------------------
' Hard-coded values.
'----------------------------------------------------------------------------------------------------
Public Const PRINTSHEET_SUBDIR = "PRINT"    ' Hardcoded printed datasheet directory (below folder with .DAT files).
Public Const NUMPTS = 5                     ' Hardcoded number of points for accuracy/linearity measurements.
Public Const NUMTESTS = 20                  ' Hardcoded maximum array index (# of stored tests) for STATUS (strTestDATSTRING) and other arrays.

' Global variables.
Public strDBFILEname As String              ' Global variable to hold database (.DAT) file name.
Public strDBFILEfolder As String            ' Global variable to hold database (.DAT) file folder.
Public strDATFILEname As String             ' Global variable to hold stored datasheet data (.DAT) file name.
Public strDATFILEfolder As String           ' Global variable to hold stored datasheet data (.DAT) file folder.
Public iFileCount As Integer                ' Count of number of text datasheet files "printed".
Public iDupCount As Integer                 ' Count of number of text datasheet files "printed" over an existing file.
Public bDisplayMessages As Boolean          ' Flag, "True" to display error messages in various functions and subroutines.
Public bPrintFailingUnits As Boolean        ' Flag, "True" to also print text log files from failing units.

' Global arrays.
Public strTestNAMES(1 To NUMTESTS) As String    ' Global array for the Final Test test names.
Public strTestUNITS(1 To NUMTESTS) As String    ' Global array for the Final Test test units.
Public strTSPEC(1 To NUMTESTS) As String        ' Global array for the Final Test test limits strings for printed datasheet.
Public strMODNAME As String                     ' Global variable for module model name: "SCM5B30-1419", for example.
Public strSerialNumber As String                ' Global variable for work order-serial number (collectively: Serial Number).
Public strDATETESTED As String                  ' Global variable for date tested.
' Global array for the Final Test test status read from the .DAT file (this includes the "PASS" or "FAIL" status,
' test results, and the number of decimal points to display).
Public strTestDATSTRING(1 To NUMTESTS) As String
' Global arrays for the Accuracy/Linearity test data read from the .DAT file.
Public strTSIM(1 To 5) As String              ' Input value during acc/lin test (index is meas. #).
Public strOUTCALC(1 To 5) As String           ' Calculated output value during acc/lin test (index is meas. #).
Public strOUTMEAS(1 To 5) As String           ' Measured output value during acc/lin test (index is meas. #).
Public strERROROUT(1 To 5) As String          ' Calculated output error during acc/lin test (index is meas. #).
Public strACCSTAT(1 To 5) As String           ' PASS or FAILED status string during acc/lin test (index is meas. #).
' Global variable for data read from the datalog (.DAT) file.
Public sLOWV As Single                      ' Obsolete read value from datalog file.
Public sHIGHV As Single                     ' Obsolete read value from datalog file.
Public sTOTLRESPEC As Single                ' Obsolete read value from datalog file.


'================================================================================================================================
Sub Main()
    ' This is the startup (Main) subroutine for the program. Everything starts here.
        
    On Error GoTo ErrorHandler

    ' Initialize Final Test names and units for tests and stored
    ' values for data read from datalog and database files.
        
    '------------------------------------------------------
    ' Display program screen.
    ' NOTE: if screen is shown modal, it will NOT show up
    ' in the taskbar nor be found by clicking alt-tab to
    ' select open programs!
    '------------------------------------------------------
    
    'frmDBselect.Show vbModal   ' Show screen (modal).
    frmDSfiles.Show            ' Show screen (nonmodal).
    
    
    Exit Sub    ' Exit subroutine (before the error handler) if no error.
ErrorHandler:
    
    MsgBox ("Error in ""Main"" subroutine = " & Err.Description)

End Sub

Public Function funcMakePathFromFolder(ByVal strSubfolderName As String) As Boolean
    '-------------------------------------------------------------------------------------
    ' Function to create directories (folders) as needed, based on the passed parameter.
    '
    ' NOTE: The "strSubfolderName" parameter is assumed to be a complete path, including
    '       drive letter. This subroutine does not handle other path forms, such as
    '       those starting with a "\\" (as in "\\fileserver\") and will generate an
    '       error message and return "False" if an invalid folder name is passed.
    '-------------------------------------------------------------------------------------
    Dim arTemp() As String                          ' Dynamic array to store parsed values from "Split" function.
    Dim iArrayIndex As Long                         ' String-array index.
    Dim strFolder As String                           ' (Re)combined folder name string, concatenated piece by piece from original.
    Dim objFSO As New Scripting.FileSystemObject    ' New instance of FileSystemObject.
    
    On Error GoTo ErrorHandler
    
    'strFolder = sFolderRoot & "\"   ' Initialize to root.
    'strFolder = Left$(strSubfolderName, 2) & "\"  ' Initialize to drive letter and backslash.
    strFolder = ""    ' Initialize to drive letter and backslash.
    
    arTemp = Split(strSubfolderName, "\")            ' Split "full" folder name to array of strings at each backslash.
    
    ' For each split string (folder name) check if folder already exists. Lower and upper bounds of array are determined
    ' by the array itself (the number of strings depends on the contents of the "full" folder name (complete path). The
    ' initial string should be the drive name. If the folder does not exist, it is created. The "combined" folder name is
    ' then re-combined by adding a backslash and then the next string in the array (the next folder name).
    For iArrayIndex = LBound(arTemp) To UBound(arTemp)
        strFolder = strFolder & arTemp(iArrayIndex) & "\"
        If Not objFSO.FolderExists(strFolder) Then
            Call objFSO.CreateFolder(strFolder)
        End If
    Next iArrayIndex
    Set objFSO = Nothing
    
    funcMakePathFromFolder = True    ' Set function return before exit.
    
    Exit Function ' Exit subroutine (before the error handler) if no error.
ErrorHandler:
    Set objFSO = Nothing
    funcMakePathFromFolder = False    ' Set function error return.
    MsgBox ("Error in function ""funcMakePathFromFolder"" = " & Err.Description & vbCrLf & _
        "Folder name = " & strFolder & vbCrLf & _
        "Function returning ""False""!")
End Function

Public Sub subDirListFSO(ByVal strFolderName As String)
    '
    '
    'Declare the variables.
    Dim objFSO As FileSystemObject
    Dim objFolder As Folder
    Dim objFile As File
    Dim NextRow As Long
    Dim iCount As Integer
    
    On Error GoTo ErrorHandler
    
    'Create an instance of the FileSystemObject.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Get the folder.
    Set objFolder = objFSO.GetFolder(strFolderName)
    
    'If the folder does not contain files, exit the sub.
    'If (objFolder.Files.Count = 0) Then
    '    MsgBox "No files were found...", vbExclamation
    '    Exit Sub
    'End If
    
    iCount = 0  'Initialize.
    
    'Loop through each file in the folder
    For Each objFile In objFolder.Files
        frmDSfiles.lstInvalidDS.AddItem objFile.Name
        iCount = iCount + 1
        frmDSfiles.txtInvalidCount.Text = iCount
    Next objFile
 
 
    Exit Sub    'Exit before error handler.
ErrorHandler:
    MsgBox ("Error in ""subDirListFSO"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Sub

Public Sub subDirList(ByVal strFolderName As String)
    '
    '
    'Declare the variables.
    Dim strFileName As String
    Dim strDirSpec As String
    Dim lCountInvalid As Long
    Dim lCountRename As Long
    Dim lCountAll As Long
    Dim strMoveLoc As String
    Dim strLogFileNameLoc As String
    Dim strDatasheetLoc As String
       
    On Error GoTo ErrorHandler
    
    
    'Initialize file names and locations.
    'This is TEMPORARY, since they should
    'eventually be read from a file.
    strMoveLoc = "C:\_CODE\DFWDS\Bad_Datasheets"
    strLogFileNameLoc = "C:\_CODE\DFWDS\Log\DFWDS.log"
    strDatasheetLoc = "C:\_CODE\DFWDS\WebDatasheets"
    
    'Initialize.
    lCountInvalid = 0
    lCountRename = 0
    lCountAll = 0
    frmDSfiles.lstInvalidDS.Clear
    frmDSfiles.lstRenameDS.Clear
    
    'Set Dir$ function specification (directory path and search criteria).
    'strDirSpec = strFolderName & "\*.txt"
    strDirSpec = strFolderName & "\*.*"
    strFileName = Dir$(strDirSpec, vbNormal)
    
    'Loop through each file in the folder
    Do While (strFileName <> "")
        strFileName = Dir$
        If (strFileName <> "") Then
            Call subProcessDSfile(strFileName, strMoveLoc, strLogFileNameLoc, lCountRename, lCountInvalid)
            lCountAll = lCountAll + 1   'Increment total count.
        End If
    Loop
    
    'Set count displays.
    frmDSfiles.txtInvalidCount.Text = lCountInvalid
    frmDSfiles.txtRenameCount.Text = lCountRename
    frmDSfiles.txtAllCount.Text = lCountAll
    frmDSfiles.Refresh
 
    Exit Sub    'Exit before error handler.
ErrorHandler:
    MsgBox ("Error in ""subDirList"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Sub

Private Sub subProcessDSfile(ByVal strDSfileName As String, ByVal strDSmoveLocation As String, ByVal strDSlogNameLoc As String, _
    ByRef lCountRename As Long, ByRef lCountInvalid As Long)
    '-------------------------------------------------------------------------------------------------------------
    'Subroutine to process the passed file name. If it is determined to be an invalid name for the Dataforth
    'website, the file is moved to the passed directory location and this action is recorded in a log file
    'whose name and location is also passed as a parameter. If the file name matches the format of "encoded"
    'datasheet file names from the DOS test programs, the file is renamed to the appropriate "unencoded"
    'datasheet file name and this action is also recorded to the specified log file. The subroutine posts
    'error messages for problems that may be encountered during file processing.
    '
    '   Inputs:
    '       strDSfileName:      Datasheet file name.
    '       strDSmoveLocation:  Directory location that invalid files are copied. Invalid files include non-text
    '                           files and files with names that do not match the format for the Dataforth website.
    '       strDSlogNameLoc:    Directory location and file name of log file to record datasheet file moves and
    '                           renames.
    '       lCountInvalid:      Passes count of invalid datasheet files back to the calling routine
    '                           by reference for status displays, etc. Also used, on first call,
    '                           to pass the initial count from the calling routine (see entry in
    '                           "Inputs", above).
    '       lCountRename:       Passes initial count of renamed datasheet files to the subroutine.
    '                           Also used to pass total count back to the calling routine for status
    '                           displays (see entry in "Outputs", below).
    '   Outputs:
    '       Error messages, log file entries.
    '       lCountInvalid:      Passes count of invalid datasheet files back to the calling routine
    '                           by reference for status displays, etc. Also used, on first call,
    '                           to pass the initial count from the calling routine (see entry in
    '                           "Inputs", above).
    '       lCountRename:       Passes count of renamed datasheet files back to the calling routine
    '                           by reference for status displays, etc. Also used, on first call,
    '                           to pass the initial count from the calling routine (see entry in
    '                           "Inputs", above).
    '-------------------------------------------------------------------------------------------------------------
    '
    'Define the local variables.
    Dim strWorkOrderNum As String   'Work order number.
    Dim strFullFileName As String   'Full file name (including extension).
    Dim strFileNameOnly As String   'File name (only).
    Dim iDashLoc As Integer         'Dash location in file name (only) string.
    Dim iFNOlength As Integer       'Length of file name (only) string.
    Dim strWOdecoded As String      'Work order number.
    
    On Error GoTo ErrorHandler
    
    'Get uppercase-only version of the full file name.
    'This is necessary for later processing of the
    'datasheet files (including determining whether
    'they are validly-named datasheet files).
    strFullFileName = UCase$(strDSfileName)
    
    'Get the file name (only). This should be the (encoded
    'or unencoded) module serial number. Note that the
    'function requires a full file name already in
    'all-UPPERCASE.
    strFileNameOnly = funcGetFileNameOnly(strFullFileName)
    
    'Check for text file.
    If (strFileNameOnly = "") Then
        'Not a text file (null return from funcGetFileNameOnly).
        'Move file to specified location and log action to specified log file.
        Call subDSmove(strFullFileName, strDSmoveLocation, strDSlogNameLoc, lCountInvalid)
        Exit Sub    'Exit early for non-text file.
    End If

    'Check for valid dash location (and/or existence) and a valid dash number.
    iDashLoc = funcGetDashLoc(strFileNameOnly)    'Get dash location.
    
    'Check for valid location.
    If Not (funcGetDashLoc(strFileNameOnly) > 0) Then
        'Dash (or dash number) is not valid.
        'Move file to specified location and log action to specified log file.
        Call subDSmove(strFullFileName, strDSmoveLocation, strDSlogNameLoc, lCountInvalid)
        Exit Sub    'Exit early for non-datasheet file (no or invalid dash or invalid dash number).
    End If

    'Parse work order# (characters to the left of
    'the dash) from the serial number string.
    strWorkOrderNum = Left$(strFileNameOnly, iDashLoc - 1)

    If (funcIsAllNumbers(strWorkOrderNum) = True) Then
        'Work order number string is all numbers,
        'check for leading "0".
        If (Left$(strWorkOrderNum, 1) = "0") Then
            'Leading "0" in all-numeric work order number. Work order number is not valid.
            'Move file to specified location and log action to specified log file.
            Call subDSmove(strFullFileName, strDSmoveLocation, strDSlogNameLoc, lCountInvalid)
            Exit Sub    'Exit early for non-datasheet file (no or invalid dash or invalid dash number).
        End If
    Else
        'Work order string is not all numbers. Check if
        'it is matches the format of a DOS-encoded work
        'order number.
        If (funcISrenameWO(strWorkOrderNum) = True) Then
            'DOS-encoded work order number. Rename file
            'to unencoded datasheet file name.
            Call subDSrename(strFullFileName, strDSlogNameLoc, lCountRename)
        Else
            'Not a DOS-encoded work order number. Work order number is not valid.
            'Move file to specified location and log action to specified log file.
            Call subDSmove(strFullFileName, strDSmoveLocation, strDSlogNameLoc, lCountInvalid)
            Exit Sub    'Exit early for non-datasheet file (no or invalid dash or invalid dash number).
        End If
    End If

    Exit Sub      'Exit before error handler.
ErrorHandler:
    MsgBox ("Error in ""subProcessDSfiles"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Sub

Private Function funcGetFileNameOnly(ByVal strFullFileName As String) As String
    '----------------------------------------------------------------------------------------------------
    'This function returns the file name (only) portion of the full file name (file name plus extension).
    'The file name, in the case of datasheet files, is the module serial number. This is returned
    'if the proper file extension is found (".TXT"). If the proper extension is not found,
    'or there is some other problem (such as a blank file name passed to the function), a null string
    'is returned.
    '
    'NOTE:  The passed full file name must be in all-UPPERCASE for the ".TXT" check to work.
    '----------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    Dim strSerial As String     'Serial number portion of the complete file name (file name, without the extension).
    Dim iSTRlength As Integer   'Length of serial number or complete file name string.
    
    On Error GoTo ErrorHandler
    
    If (strFullFileName <> "") Then
        'Get serial number (file name) from complete file name.
        If (Right$(strFullFileName, 4) = ".TXT") Then
            'Strip off last four characters (.TXT file extension) from full file name
            'to create the file name only (serial number) string.
            iSTRlength = Len(strFullFileName)                   'Get length of the full file name.
            strSerial = Left$(strFullFileName, iSTRlength - 4)  'Strip off last four characters (".txt").
            funcGetFileNameOnly = strSerial
        Else
            funcGetFileNameOnly = ""  'Error value.
        End If
    Else
        'Invalid (null) file name.
        funcGetFileNameOnly = ""  'Error value.
    End If

    Exit Function ' Exit before error handler.
ErrorHandler:
    funcGetFileNameOnly = ""  'Error value.
    MsgBox ("Error in ""funcGetFileNameOnly"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Function

Function funcIsAllNumbers(ByVal strTestString As String) As Boolean
    '----------------------------------------------------------------------------------------------------
    'Function that checks whether the passed string consists of only numerical characters. The function
    'returns "True" if each character in the string is a number, and "False" if any character is not
    'a number or if there is some other problem in the function.
    '----------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    Dim strChar As String
    Dim iDx As Integer
    
    On Error GoTo ErrorHandler
    
    'Initialize to "all numbers" value.
    funcIsAllNumbers = True
    
    For iDx = 1 To Len(strTestString)   'Loop from 1st character to last character of string.
        'See if the next character is a non-number.
        strChar = Mid$(strTestString, iDx, 1)           'Get next character.
        If ((strChar < "0") Or (strChar > "9")) Then    'Character is not "0" through "9".
            funcIsAllNumbers = False                    'Set "not all numbers" value.
            Exit For                                    'Exit the loop (no need to continue after first non-number).
        End If
    Next iDx

    Exit Function ' Exit before error handler.
ErrorHandler:
    funcIsAllNumbers = False    'Error ("not all numbers") value.
    MsgBox ("Error in ""funcIsAllNumbers"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Function

Private Function funcGetDashLoc(ByVal strFileNameOnly As String) As Integer
    '----------------------------------------------------------------------------------------------------
    'This function returns the dash ("-") location in the passed file name (only) string. It returns
    'an error value of "0" if no dash is found, or more than one dash is found, if there are more
    'than one characters after the dash, and if any of the characters after the dash are not a
    'number, or if there are any other problems in the function.
    '----------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    Dim iSTRlength As Integer   'Length of serial number string.
    Dim iDashLocL As Integer    'Location of dash, when searched for from the left.
    Dim iDashLocR As Integer    'Location of dash, when searched for from the right.
    Dim strDashNum As String    'Dash number string.
    
    On Error GoTo ErrorHandler
    
    iSTRlength = Len(strFileNameOnly)   'Length of file name (only) string.
    
    'Location of dash (characters from start (left) of string) when searched from the left.
    iDashLocL = InStr(strFileNameOnly, "-")
    
    'Location of dash (characters from start (left) of string) when searched from the right.
    iDashLocR = InStrRev(strFileNameOnly, "-")
    
    If (iDashLocL = iDashLocR) Then
        'Dash in same location = only one dash in the string.
        '
        'Start dash location validation.
        If (((iSTRlength - iDashLocL) > 2) Or ((iSTRlength - iDashLocL) = 0)) Then
            'Too many characters after the dash, or dash at end (dash number
            'more than two characters, or less than one).
            funcGetDashLoc = 0     'Error value (invalid dash).
        Else
            'Dash number is one or two characters. Get for an all-number dash number.
            strDashNum = Mid$(strFileNameOnly, iDashLocL + 1, iSTRlength - iDashLocL)
            If (funcIsAllNumbers(strDashNum) = True) Then
                'Dash number is all numbers.
                funcGetDashLoc = iDashLocL 'Good value (valid dash).
            Else
                'Dash number is not valid (not all numbers).
                funcGetDashLoc = 0         'Error value (invalid dash).
            End If
        End If
    Else
        'More than one dash in the serial string.
        funcGetDashLoc = 0         'Error value (invalid dash).
    End If

    Exit Function 'Exit before error handler.
ErrorHandler:
    funcGetDashLoc = 0     'Error (not valid) value.
    MsgBox ("Error in ""funcIsValidDash"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Function

Private Function funcDecodeWOchar(ByVal strWOnum As String) As String
    '----------------------------------------------------------------------------------------------------
    'This function returns a two-character string decoded from the first character of the
    'passed work order number string. If the first character is "A" through "J", the
    'function returns "10" through "19", respectively, which represents the values that
    'are encoded in valid DOS-encoded datasheet file names. If the first character is
    'not "A" or "J" or a letter in between, or if there is some problem in the function,
    'the function returns a null string.
    '----------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    Dim strFirstChar As String  'First character in passed work order number string.
    
    On Error GoTo ErrorHandler
    
    If (strWOnum = "") Then
        'Null string, return error value (null string).
        funcDecodeWOchar = ""   'Error value.
    Else
        'String has at least one character, check for "A" through "J".
        strFirstChar = Left$(strWOnum, 1)   'Get first character of passed work order number.
        Select Case strFirstChar
            Case strFirstChar = "A"
                funcDecodeWOchar = "10" 'Decode of first character.
            Case strFirstChar = "B"
                funcDecodeWOchar = "11" 'Decode of first character.
            Case strFirstChar = "C"
                funcDecodeWOchar = "12" 'Decode of first character.
            Case strFirstChar = "D"
                funcDecodeWOchar = "13" 'Decode of first character.
            Case strFirstChar = "E"
                funcDecodeWOchar = "14" 'Decode of first character.
            Case strFirstChar = "F"
                funcDecodeWOchar = "15" 'Decode of first character.
            Case strFirstChar = "G"
                funcDecodeWOchar = "16" 'Decode of first character.
            Case strFirstChar = "H"
                funcDecodeWOchar = "17" 'Decode of first character.
            Case strFirstChar = "I"
                funcDecodeWOchar = "18" 'Decode of first character.
            Case strFirstChar = "J"
                funcDecodeWOchar = "19" 'Decode of first character.
            Case Else
                'Not "A" through "J"
                funcDecodeWOchar = ""   'Error value.
        End Select
    End If

    Exit Function ' Exit before error handler.
ErrorHandler:
    funcDecodeWOchar = ""  'Error value.
    MsgBox ("Error in ""funcDecodeWOchar"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Function

Private Function funcISrenameWO(ByVal strWOnumber) As Boolean
    '----------------------------------------------------------------------------------------------------
    'This function returns "True" if the passed work order number matches the format of a DOS-encoded
    'work order number (for work orders above the value of "99,999"). A DOS-encoded work order number
    'will be five characters long, start with "A" through "J", and have all numbers for the remaining
    'characters. The function will return "False" if any of these conditions are not true, or there is
    'any other problem in the function.
    '----------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    Dim strLastFour As String
    Dim strFirstOne As String
    
    On Error GoTo ErrorHandler
    
    If (Len(strWOnumber) <> 5) Then
        'Not five characters long.
        funcISrenameWO = False      'Set "not a valid rename string" value.
    Else
        strFirstOne = UCase$(Left$(strWOnumber, 1))
        If ((strFirstOne < "A") Or (strFirstOne > "J")) Then
            'First character not "A" through "J".
            funcISrenameWO = False      'Set "not a valid rename string" value.
        Else
            strLastFour = Right$(strWOnumber, 4)
            If (funcIsAllNumbers(strLastFour) = True) Then
                funcISrenameWO = True      'Set "valid rename string" value.
            Else
                'Last four characters not all numberss.
                funcISrenameWO = False      'Set "not a valid rename string" value.
            End If
        End If
    End If

    Exit Function ' Exit before error handler.
ErrorHandler:
    funcISrenameWO = False      'Error value (not valid "rename" string).
    MsgBox ("Error in ""funcISrenameWO"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Function

Private Sub subDSmove(ByVal strFullFileName As String, ByVal strDSmoveLocation As String, _
    ByVal strDSlogNameLoc As String, ByRef lCountInvalid As Long)
    '-------------------------------------------------------------------------------------------------------------
    'Subroutine to move the file specified by the passed file name to the directory specified by the passed "move"
    'directory. This action is recorded in a log file whose name and location is also passed as a parameter.
    'The subroutine increments a by-reference count parameter for each file moved, which can be used for a
    'status display, such as "total invalid files", or some similar use. Errors encountered during the subroutine
    'will be logged in specified log file and error messages will be displayed.
    '
    '   Inputs:
    '       strFullFileName:    Full file name of the file to be moved (includes file extension).
    '       strDSmoveLocation:  Directory location where the file is moved.
    '       strDSlogNameLoc:    Directory location and file name of log file to record the file move.
    '       lCountInvalid:      Passes initial count of invalid datasheet files (files to be moved)
    '                           to the subroutine. Also used to pass total count back to the calling
    '                           routine for status displays (see entry in "Outputs", below).
    '   Outputs:
    '       Error messages, log file entries.
    '       lCountInvalid:      Passes count of invalid datasheet files back to the calling routine
    '                           by reference for status displays, etc. Also used, on first call,
    '                           to pass the initial count from the calling routine (see entry in
    '                           "Inputs", above).
    '-------------------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    
    On Error GoTo ErrorHandler
    

'NOTE: The code below is temporary code for debug. The "move" code is not yet in the subroutine!!!
    frmDSfiles.lstInvalidDS.AddItem strFullFileName     'Add file to be moved (invalid DS file name) to the list.
    lCountInvalid = lCountInvalid + 1                   'Increment count.



    Exit Sub      ' Exit before error handler.
ErrorHandler:
    MsgBox ("Error in ""subDSmove"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Sub

Private Sub subDSrename(ByVal strFullFileName As String, ByVal strDSlogNameLoc As String, ByRef lCountRename As Long)
    '-------------------------------------------------------------------------------------------------------------
    'Subroutine to rename the DOS-encoded datasheet file specified by the passed full file name and to recorded
    'this action in a log file whose name and location is also passed as a parameter. This subroutine is run
    'after a datasheet file with a DOS-encoded name is found (this is a valid datasheet file name with five
    'characters for the work order number, the first character "A" through "J", and all of the remaining work
    'order number characters are a number). The "A" through "J" first character is renamed to the appropriate
    'two-number "decoded" value ("10" through "19"), while the remaining characters in the file name portion of
    'the full datasheet file name remain unchanged. The subroutine increments a by-reference count parameter for
    'each file renamed, which can be used for a "total files renamed" status display, or some similar use. Errors
    'encountered during the subroutine will be logged in specified log file and error messages will be displayed.
    '
    '   Inputs:
    '       strFullFileName:    Full file name of the file to be moved (includes file extension).
    '       strDSlogNameLoc:    Directory location and file name of log file to record the file move.
    '       lCountRename:       Passes initial count of renamed datasheet files to the subroutine.
    '                           Also used to pass total count back to the calling routine for status
    '                           displays (see entry in "Outputs", below).
    '   Outputs:
    '       Error messages, log file entries.
    '       lCountRename:       Passes count of renamed datasheet files back to the calling routine
    '                           by reference for status displays, etc. Also used, on first call,
    '                           to pass the initial count from the calling routine (see entry in
    '                           "Inputs", above).
    '-------------------------------------------------------------------------------------------------------------
    '
    'Define the variables.
    
    On Error GoTo ErrorHandler
    

'NOTE: The code below is temporary code for debug. The "rename" code is not yet in the subroutine!!!
    frmDSfiles.lstRenameDS.AddItem strFullFileName  'Add file to be renamed to the list.
    lCountRename = lCountRename + 1                 'Increment count.


    Exit Sub      ' Exit before error handler.
ErrorHandler:
    MsgBox ("Error in ""subDSrename"" = " & Err.Description & vbCrLf & vbCrLf & _
            "Contact engineering before proceeding!"), vbCritical
End Sub

