Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.FileIO

Public Class ChangeLocale
    Inherits System.Windows.Forms.Form
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer

    ' ShowWindow() Commands
    Public Const SW_HIDE As Short = 0
    Public Const SW_SHOWNORMAL As Short = 1
    Public Const SW_NORMAL As Short = 1
    Public Const SW_SHOWMINIMIZED As Short = 2
    Public Const SW_SHOWMAXIMIZED As Short = 3
    Public Const SW_MAXIMIZE As Short = 3
    Public Const SW_SHOWNOACTIVATE As Short = 4
    Public Const SW_SHOW As Short = 5
    Public Const SW_MINIMIZE As Short = 6
    Public Const SW_SHOWMINNOACTIVE As Short = 7
    Public Const SW_SHOWNA As Short = 8
    Public Const SW_RESTORE As Short = 9
    Public Const SW_SHOWDEFAULT As Short = 10
    Public Const SW_MAX As Short = 10

    Dim fileName As String
    Dim flag As Boolean
    Dim FolderPath As String
    Dim Locales(100, 2) As String
    Dim strSEFileType() As String = {"*.asm", "*.dft", "*.par", "*.psm", "*.pwd"}
    Dim Locale As Integer

    Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
        Dim PropSets As SolidEdgeFileProperties.PropertySets = Nothing
        Dim Properties As SolidEdgeFileProperties.Properties = Nothing
        Dim Prop As SolidEdgeFileProperties.Property = Nothing
        Dim VerifyValue As Integer
        Dim NewLine As String
        Dim strTitle As String
        Dim Message As String
        Dim Response As Object
        Dim strFiles() As String = Nothing
        Dim bIsInputFile As Boolean
        Dim i As Short
        Dim LogFile As Short
        Dim LogFileClosed As Boolean
        Dim bNotReady, bGarbage As Boolean

        bNotReady = False
        LogFileClosed = True
        bGarbage = True
        bIsInputFile = False
        strTitle = "Change Solid Edge CreationLocale Property"
        NewLine = Chr(10) & Chr(13)

        'Disable this button until processing is complete
        btnProcess.Enabled = False

        bNotReady = (("" = txtLogFile.Text) And optAllFiles.Checked = True)
        bNotReady = (("" = fileName) And optOneFile.Checked = True)
        bNotReady = ("" = cboLocale.Text)

        If bNotReady Then
            Message = "You must select a Solid Edge file and set the target CreationLocale first."
            MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
            GoTo GracefulExit
        End If

        If optAllFiles.Checked Then
            If FileExists((txtLogFile.Text)) Then
                Response = MsgBox(txtLogFile.Text & " exists.  Do you want to overwrite it?", MsgBoxStyle.YesNo, strTitle)
                If Response = MsgBoxResult.Yes Then
                    If Not LogFileClosed Then
                        FileClose(LogFile)
                        LogFileClosed = True
                    End If
                    Kill(txtLogFile.Text)
                Else
                    bGarbage = False
                    GoTo GracefulExit
                End If
            End If
            LogFile = FreeFile()
            FileOpen(LogFile, txtLogFile.Text, OpenMode.Output, OpenAccess.Write)
            LogFileClosed = False
            LoadSEFiles(FolderPath, strFiles, bIsInputFile)
            If Not bIsInputFile Then
                Message = "There are no Solid Edge files in the path you selected."
                MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                GoTo GracefulExit
            End If
        Else
            ReDim strFiles(0)
            strFiles(0) = fileName
            bIsInputFile = Not ("" = fileName)
        End If

        For i = LBound(strFiles) To UBound(strFiles)
            lblProcess.Text = "Processing File " & i + 1 & " of " & UBound(strFiles) + 1
            lblProcess.Update()
            If optAllFiles.Checked Then
                txtOneFile.Text = strFiles(i)
                Message = "Setting creation locale of " & strFiles(i) & " to " & cboLocale.Text & "."
                WriteLine(LogFile, Message)
            End If
            ' Connect to the Applicaiton
            On Error Resume Next
            PropSets = Nothing

            PropSets = New SolidEdgeFileProperties.PropertySets
            If Err.Number <> 0 Then
                Message = "ERROR while accessing the File Properties client." & NewLine
                Message = Message & "Ensure Solid Edge is installed but not running."
                If optOneFile.Checked = True Then
                    MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                Else
                    WriteLine(LogFile, Message)
                End If
                GoTo GracefulExit
            End If

            PropSets.Open((strFiles(i)))
            If Err.Number <> 0 Then
                Message = "ERROR while opening " & strFiles(i) & "." & NewLine
                Message = Message & "Ensure no other application is accessing strFiles(i)." & NewLine
                Message = Message & "Ensure strFiles(i) is not write-protected."
                If optOneFile.Checked = True Then
                    MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                Else
                    WriteLine(LogFile, Message)
                End If
                GoTo NextLoop
            End If
            'On Error GoTo BadError
            Properties = PropSets.Item("ExtendedSummaryInformation")
            Prop = Properties.PropertyByID(SolidEdgeFileProperties.PropertyIDs.igExtSumInfoCreationLocale)

            If Prop.Value = Locale Then
                If optOneFile.Checked = True Then
                    Message = "The CreationLocale of " & strFiles(i) & " is already set to " & cboLocale.Text & "." & NewLine
                    Message = Message & "If you reset the CreationLocale to " & cboLocale.Text & " now, the Modified attribute of this file will be set to the current time and date." & NewLine
                    Message = Message & "Is this what you want?"
                    If MsgBox(Message, MsgBoxStyle.YesNo, strTitle) = MsgBoxResult.No Then
                        GoTo GracefulExit
                    End If
                Else
                    Message = "Skipped this file because the CreationLocale of " & strFiles(i) & " is already set to " & cboLocale.Text & "." & NewLine
                    WriteLine(LogFile, Message)
                    GoTo NextLoop
                End If
            End If

            Prop.Value = Locale
            VerifyValue = Prop.Value
            Properties.Save()
            PropSets.Close()

            ' now need to do .Net garbage collection to release all the objects.
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(PropSets)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Properties)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Prop)
            System.GC.Collect(System.GC.MaxGeneration)
            System.GC.WaitForPendingFinalizers()
            System.GC.Collect(System.GC.MaxGeneration)  'per MS, should do this again to be sure everything is released.
            PropSets = Nothing
            Properties = Nothing
            Prop = Nothing

            'Do it all again to verify the new value
            On Error Resume Next
            PropSets = New SolidEdgeFileProperties.PropertySets

            If Err.Number <> 0 Then
                Message = "ERROR: could not verify the changed CreationLocale property."
                If optOneFile.Checked = True Then
                    MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                Else
                    WriteLine(LogFile, Message)
                End If
                GoTo NextLoop
            End If
            'On Error GoTo BadError
            PropSets.Open((strFiles(i)))
            Properties = PropSets("ExtendedSummaryInformation")
            Prop = Properties.PropertyByID(SolidEdgeFileProperties.PropertyIDs.igExtSumInfoCreationLocale)
            '    MsgBox "New CreationLocale value: " & Prop.Value
            If VerifyValue = Prop.Value Then
                Message = "The CreationLocale of the document has been set to " & GetValueFromIndex(VerifyValue)
                If optOneFile.Checked = True Then
                    MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                Else
                    WriteLine(LogFile, Message)
                End If
            Else
                Message = "ERROR: Could not find CreationLocale property in " & strFiles(i) & "." & NewLine
                Message = Message & "The CreationLocale was not reset."
                If optOneFile.Checked = True Then
                    MsgBox(Message, MsgBoxStyle.OkOnly, strTitle)
                Else
                    WriteLine(LogFile, Message)
                End If
            End If
            GoTo NextLoop

NextLoop:
            PropSets.Close()

            ' now need to do .Net garbage collection to release all the objects.
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(PropSets)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Properties)
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(Prop)
            System.GC.Collect(System.GC.MaxGeneration)
            System.GC.WaitForPendingFinalizers()
            System.GC.Collect(System.GC.MaxGeneration)  'per MS, should do this again to be sure everything is released.

            Prop = Nothing
            Properties = Nothing
            PropSets = Nothing

            If optAllFiles.Checked Then WriteLine(LogFile, NewLine)

        Next i

GracefulExit:
        If optAllFiles.Checked And bGarbage = True Then MsgBox("Processing complete. Results recorded in " & txtLogFile.Text)
        If optAllFiles.Checked And bGarbage = False Then MsgBox("No Files were processed")
        FileClose(LogFile)
        PropSets.Close()
        ' now need to do .Net garbage collection to release all the objects unless the user does not overwrite log file.
        If bGarbage = True Then System.Runtime.InteropServices.Marshal.FinalReleaseComObject(PropSets)
        System.GC.Collect(System.GC.MaxGeneration)
        System.GC.WaitForPendingFinalizers()
        System.GC.Collect(System.GC.MaxGeneration)  'per MS, should do this again to be sure everything is released.
        Prop = Nothing
        Properties = Nothing
        PropSets = Nothing

        'Re-enable this button
        btnProcess.Enabled = True
    End Sub


    Private Sub ChangeLocale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Short

        'Build Locales array
        Locales(0, 0) = "Afrikaans"
        Locales(0, 1) = "&H0436"
        Locales(1, 0) = "Arabic (Saudi Arabia)"
        Locales(1, 1) = "&H0401"
        Locales(2, 0) = "Arabic (Iraq)"
        Locales(2, 1) = "&H0801"
        Locales(3, 0) = "Arabic (Egypt)"
        Locales(3, 1) = "&H0C01"
        Locales(4, 0) = "Arabic (Libya)"
        Locales(4, 1) = "&H1001"
        Locales(5, 0) = "Arabic (Algeria)"
        Locales(5, 1) = "&H1401"
        Locales(6, 0) = "Arabic (Morocco)"
        Locales(6, 1) = "&H1801"
        Locales(7, 0) = "Arabic (Tunisia)"
        Locales(7, 1) = "&H1C01"
        Locales(8, 0) = "Arabic (Oman)"
        Locales(8, 1) = "&H2001"
        Locales(9, 0) = "Arabic (Yemen)"
        Locales(9, 1) = "&H2401"
        Locales(10, 0) = "Arabic (Syria)"
        Locales(10, 1) = "&H2801"
        Locales(11, 0) = "Arabic (Jordan)"
        Locales(11, 1) = "&H2C01"
        Locales(12, 0) = "Arabic (Lebanon)"
        Locales(12, 1) = "&H3001"
        Locales(13, 0) = "Arabic (Kuwait)"
        Locales(13, 1) = "&H3401"
        Locales(14, 0) = "Arabic (U.A.E)"
        Locales(14, 1) = "&H3801"
        Locales(15, 0) = "Arabic (Bahrain)"
        Locales(15, 1) = "&H3C01"
        Locales(16, 0) = "Araboc (Qata)"
        Locales(16, 1) = "&H4001"
        Locales(17, 0) = "Basque"
        Locales(17, 1) = "&H042D"
        Locales(18, 0) = "Byelorussian"
        Locales(18, 1) = "&H0423"
        Locales(19, 0) = "Bulgarian"
        Locales(19, 1) = "&H0402"
        Locales(20, 0) = "Catalan"
        Locales(20, 1) = "&H0403"
        Locales(21, 0) = "Chinese (Taiwan)"
        Locales(21, 1) = "&H0404"
        Locales(22, 0) = "Chinese (PRC)"
        Locales(22, 1) = "&H0804"
        Locales(23, 0) = "Chinese (Hong Kong)"
        Locales(23, 1) = "&H0C04"
        Locales(24, 0) = "Chinese (Singapore)"
        Locales(24, 1) = "&H1004"
        Locales(25, 0) = "Czech"
        Locales(25, 1) = "&H0405"
        Locales(26, 0) = "Danish"
        Locales(26, 1) = "&H0406"
        Locales(27, 0) = "Dutch (Standard)"
        Locales(27, 1) = "&H0413"
        Locales(28, 0) = "Dutch (Belgian)"
        Locales(28, 1) = "&H0813"
        Locales(29, 0) = "English (American)"
        Locales(29, 1) = "&H0409"
        Locales(30, 0) = "English (British)"
        Locales(30, 1) = "&H0809"
        Locales(31, 0) = "English (Canadian)"
        Locales(31, 1) = "&H1009"
        Locales(32, 0) = "English (New Zealand)"
        Locales(32, 1) = "&H1409"
        Locales(33, 0) = "English (Australian)"
        Locales(33, 1) = "&H0C09"
        Locales(34, 0) = "English (Ireland)"
        Locales(34, 1) = "&H1809"
        Locales(35, 0) = "English (South Africa)"
        Locales(35, 1) = "&H1C09"
        Locales(36, 0) = "Estonian"
        Locales(36, 1) = "&H0425"
        Locales(37, 0) = "Farsi"
        Locales(37, 1) = "&H0429"
        Locales(38, 0) = "Finnish"
        Locales(38, 1) = "&H040B"
        Locales(39, 0) = "French (Standard)"
        Locales(39, 1) = "&H040C"
        Locales(40, 0) = "French (Belgian)"
        Locales(40, 1) = "&H080C"
        Locales(41, 0) = "French (Swiss)"
        Locales(41, 1) = "&H100C"
        Locales(42, 0) = "French (Canadian)"
        Locales(42, 1) = "&H0C0C"
        Locales(43, 0) = "French (Luxembourg)"
        Locales(43, 1) = "&H140C"
        Locales(44, 0) = "German (Standard)"
        Locales(44, 1) = "&H0407"
        Locales(45, 0) = "German (Swiss)"
        Locales(45, 1) = "&H0807"
        Locales(46, 0) = "German (Austrian)"
        Locales(46, 1) = "&H0C07"
        Locales(47, 0) = "German (Liechtenstein)"
        Locales(47, 1) = "&H1407"
        Locales(48, 0) = "Greek"
        Locales(48, 1) = "&H0408"
        Locales(49, 0) = "Hebrew"
        Locales(49, 1) = "&H040D"
        Locales(50, 0) = "Hungarian"
        Locales(50, 1) = "&H040E"
        Locales(51, 0) = "Icelandic"
        Locales(51, 1) = "&H040F"
        Locales(52, 0) = "Indoniesian"
        Locales(52, 1) = "&H0421"
        Locales(53, 0) = "Italian (Standard)"
        Locales(53, 1) = "&H0410"
        Locales(54, 0) = "Italian (Swiss)"
        Locales(54, 1) = "&H0810"
        Locales(55, 0) = "Japanese"
        Locales(55, 1) = "&H0411"
        Locales(56, 0) = "Korean"
        Locales(56, 1) = "&H0412"
        Locales(57, 0) = "Latvian"
        Locales(57, 1) = "&H0426"
        Locales(58, 0) = "Lithuanian"
        Locales(58, 1) = "&H0427"
        Locales(59, 0) = "Norwegian (Bokmal)"
        Locales(59, 1) = "&H0414"
        Locales(60, 0) = "Norwegian (Nynorsk)"
        Locales(60, 1) = "&H0814"
        Locales(61, 0) = "Polish"
        Locales(61, 1) = "&H0415"
        Locales(62, 0) = "Portuguese (Standard)"
        Locales(62, 1) = "&H0816"
        Locales(63, 0) = "Portuguese (Brazilian)"
        Locales(63, 1) = "&H0416"
        Locales(64, 0) = "Romanian"
        Locales(64, 1) = "&H0418"
        Locales(65, 0) = "Russian"
        Locales(65, 1) = "&H0419"
        Locales(66, 0) = "Slovak"
        Locales(66, 1) = "&H041B"
        Locales(67, 0) = "Slovenian"
        Locales(67, 1) = "&H0424"
        Locales(68, 0) = "Spanish (Mexican)"
        Locales(68, 1) = "&H080A"
        Locales(69, 0) = "Spanish (Castilian)"
        Locales(69, 1) = "&H040A"
        Locales(70, 0) = "Spanish (Modern)"
        Locales(70, 1) = "&H0C0A"
        Locales(71, 0) = "Swedish"
        Locales(71, 1) = "&H041D"
        Locales(72, 0) = "Thai"
        Locales(72, 1) = "&H041E"
        Locales(73, 0) = "Turkish"
        Locales(73, 1) = "&H041F"
        Locales(74, 0) = "Ukrainian"
        Locales(74, 1) = "&H0422"

        For i = 0 To 74
            cboLocale.Items.Add(Locales(i, 0))
        Next

        FolderPath = System.Windows.Forms.Application.StartupPath()
        FolderBrowserDialog1.SelectedPath = FolderPath

        'FolderPath = "C:\temp"
        'txtLogFile.Text = FolderPath & "\ChangeLocale.txt"
        'FolderBrowserDialog1.SelectedPath = FolderPath
        btnProcess.Enabled = False
    End Sub

    Private Sub btnFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFolder.Click
        FolderBrowserDialog1.ShowDialog()
        FolderPath = FolderBrowserDialog1.SelectedPath
        FileSystem.CurrentDirectory = FolderPath

        lblFolder.Text = "Folder Path: " & FolderPath
        lblFolder.Update()

        Dim FileName As String
        Dim lenPath, len As Integer

        lenPath = FolderPath.Length

        For Each foundFile As String In FileSystem.GetFiles(FolderPath, SearchOption.SearchTopLevelOnly)
            len = foundFile.Length
            FileName = foundFile.Substring(lenPath + 1, len - lenPath - 1)
            lstFiles.Items.Add(FileName)
        Next

    End Sub

    Private Sub lstFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstFiles.SelectedIndexChanged
        txtOneFile.Text = FolderPath & "\" & lstFiles.SelectedItem
        fileName = txtOneFile.Text
    End Sub

    Private Sub optAllFiles_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optAllFiles.CheckedChanged
        If sender.Checked Then

            txtLogFile.Text = FolderPath & "\ChangeLocale.txt"
            FolderBrowserDialog1.SelectedPath = FolderPath

            If optOneFile.Checked = True Then
                txtOneFile.Enabled = True
                txtLogFile.Enabled = False
                btnLogFile.Enabled = False
                chkSubFolders.Enabled = False
            Else
                txtOneFile.Enabled = False
                txtLogFile.Enabled = True
                btnLogFile.Enabled = True
                chkSubFolders.Enabled = True
            End If

        End If
    End Sub

    Private Sub btnLogFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogFile.Click
        SaveFileDialog1.FileName = "ChangeLocale.txt"
        SaveFileDialog1.ShowDialog()
        If SaveFileDialog1.FileName <> "" Then
            txtLogFile.Text = SaveFileDialog1.FileName
        End If

    End Sub

    Private Sub txtLogFile_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLogFile.DoubleClick
        OpenFile(txtLogFile)
    End Sub


    Private Sub optOneFile_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optOneFile.CheckedChanged
        If sender.Checked Then

            If optOneFile.Checked = True Then
                txtOneFile.Enabled = True
                txtLogFile.Enabled = False
                btnLogFile.Enabled = False
                chkSubFolders.Enabled = False
            Else
                txtOneFile.Enabled = False
                txtLogFile.Enabled = True
                btnLogFile.Enabled = True
                chkSubFolders.Enabled = True
            End If

        End If

    End Sub

    Private Sub cboLocale_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLocale.SelectedIndexChanged
        Dim i As Short
        btnProcess.Enabled = True
        For i = 0 To cboLocale.Items.Count - 1
            If Locales(i, 0) = cboLocale.SelectedItem Then
                Locale = Locales(i, 1)
                Exit For
            End If
        Next i
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Close()
    End Sub

    Function GetValueFromIndex(ByRef IndexValue As Integer) As String

        Dim i As Short
        GetValueFromIndex = "Unknown CreationLocale value!"
        For i = 0 To (cboLocale.Items.Count - 1)
            If Locales(i, 1) = IndexValue Then
                GetValueFromIndex = Locales(i, 0)
                Exit For
            End If
        Next i

    End Function


    Private Function IsInitializedArrayOfStrings(ByRef strArray() As String) As Boolean

        Dim lL As Integer 'lower bound of array
        Dim lU As Integer 'upper bound of array

        On Error GoTo ErrExit

        lL = LBound(strArray)
        lU = UBound(strArray)

        IsInitializedArrayOfStrings = (lU >= lL)
        Exit Function

ErrExit:
        Err.Clear()
        IsInitializedArrayOfStrings = False

    End Function

    Public Sub OpenFile(ByRef TxtBox As System.Windows.Forms.TextBox)

        Const lpOperation As String = "open"

        If FileExists((TxtBox.Text)) Then
            Call ShellExecute(TxtBox.FindForm.Handle.ToInt32, lpOperation, TxtBox.Text, "", "", SW_SHOW)
        Else
            MsgBox("File " & TxtBox.Text & " does not exist.")
        End If

    End Sub
    Function FileExists(ByRef TestFile As String) As Boolean

        Dim value As Boolean
        Dim ret As String

        On Error Resume Next
        ret = CStr(FileDateTime(TestFile))
        value = Err.Number = 0
        If Err.Number <> 0 Then
            Debug.Print(Err.Number)
            Debug.Print(Err.Description)
        End If
        FileExists = value

    End Function
    Sub LoadSEFiles(ByRef strDir As String, ByRef strFiles() As String, ByRef bFoundAnSEFile As Boolean)
        ' Find all Solid Edge files in the strDir folder and put them into the input
        ' array of strings.  Let the calling function know whether you found anything.

        Dim courier As String
        Dim i As Short
        Dim strNewDirs() As String
        Dim bNestedFoundAnSeFile As Boolean

        bFoundAnSEFile = False 'Keep track of whether or not you found any files

        ChDrive(strDir) 'FileList.Path
        ChDir(strDir)

        For i = LBound(strSEFileType) To UBound(strSEFileType)
            ' Loop through all of the SE file types and read all the files
            'Find a file of the current type
            courier = Dir(strSEFileType(i))
            Do While courier <> "" 'if you found a file, keep going
                ' Debug.Print courier
                bFoundAnSEFile = True 'Keep track of whether or not you found any files
                If Not IsInitializedArrayOfStrings(strFiles) Then 'only do this once
                    ReDim strFiles(0) 'initialize the array
                Else
                    ReDim Preserve strFiles(UBound(strFiles) + 1) 'increment the array
                End If
                strFiles(UBound(strFiles)) = strDir & "\" & courier
                courier = Dir()
            Loop
        Next i

        If chkSubFolders.CheckState = System.Windows.Forms.CheckState.Checked Then
            ' Build an array of subdirectories
            courier = Dir(strDir & "\", FileAttribute.Directory) ' Retrieve the first entry.
            Do While courier <> "" ' Start the loop.
                ' Ignore the current directory and the encompassing directory.
                If courier <> "." And courier <> ".." Then
                    ' Use bitwise comparison to make sure MyName is a directory.
                    If (GetAttr(strDir & "\" & courier) And FileAttribute.Directory) = FileAttribute.Directory Then
                        If Not IsInitializedArrayOfStrings(strNewDirs) Then
                            ReDim strNewDirs(0)
                        Else
                            ReDim Preserve strNewDirs(UBound(strNewDirs) + 1)
                        End If
                        strNewDirs(UBound(strNewDirs)) = strDir & "\" & courier
                    End If ' it represents a directory.
                End If
                courier = Dir() ' Get next entry.
            Loop
        End If

        If IsInitializedArrayOfStrings(strNewDirs) Then
            'We can only get here if chkSubFolders.value is true and the previous block
            'resulted in finding subfolders.  Now we'll recursively call ourself in each subfolder
            For i = LBound(strNewDirs) To UBound(strNewDirs)
                Call LoadSEFiles(strNewDirs(i), strFiles, bNestedFoundAnSeFile)
                If Not bFoundAnSEFile Then 'if we already found a file, dont reset
                    bFoundAnSEFile = bNestedFoundAnSeFile
                End If
            Next i
        End If

    End Sub

End Class
