Option Explicit Private Sub cmdExit_Click() End End Sub Private Sub cmdExport_Click() Dim MyText, MyLine, MyChar, FileExt As String Dim FileName, Category, PathName, IllegalCharacters As String Dim FileIn, FileOut, I, J, Counter As Integer 'Set some initial values MyText = "" FileExt = "" If chkTextExt = 1 Then FileExt = ".txt" Counter = 0 IllegalCharacters = "/\|:*?<>" & Chr(34) 'Chr34 is a double-quote 'On Error GoTo ExportError If txtSource = "" Then MsgBox "You need to pick an input file name first" Exit Sub Else FileIn = FreeFile Open txtSource For Input As FileIn End If PathName = Left(Drive1.Drive, 2) & "/Notes/" If Dir(PathName, vbDirectory) = "" Then MkDir PathName cmdExport.Enabled = False cmdExport.Caption = "Notes 0" 'Read the file line by line until end of file Do While Not EOF(FileIn) ' Loop until end of file. Line Input #FileIn, MyLine ' Read data into a string 'MsgBox "Line is '" & MyLine & "'" If MyText = "" Then 'Tests if starting new record 'The first line truncated to 20 characters will be the file name FileName = Left(MyLine, 20) 'Test FileName for illegal characters 'Loop through illegals FileName = LTrim(FileName) If FileName = "" Then GoTo EndLoop For J = 1 To Len(IllegalCharacters) MyChar = Mid(IllegalCharacters, J, 1) 'Loop through each letter of filename For I = 1 To Len(FileName) 'Compare the file name letter to the current illegal character If Mid(FileName, I, 1) = MyChar Then 'If you get a match replace the character with a "_" FileName = Left(FileName, I - 1) & "_" & _ Right(FileName, Len(FileName) - I) End If Next I Next J 'Since this is the first record, store the value MyText = MyLine Else 'Do this if you haven't just started a new memo If MyLine = "" Then 'Tests if Input got Return or LineFeed 'If so read another line. Otherwise you get a line skip 'at the end of every line Line Input #FileIn, MyLine End If If MyLine = "0" Or MyLine = "1" Then 'Test for end of memo Line Input #FileIn, MyLine 'Line after "0" or "1" is Category Category = MyLine PathName = Left(Drive1.Drive, 2) & "\Notes\" & Category & "\" 'Use MkDir Function to make directory If Dir(PathName, vbDirectory) = "" Then MkDir PathName 'Set up the output file FileOut = FreeFile FileName = PathName & FileName & FileExt Open FileName For Output As FileOut 'Write data to the output file and close Print #FileOut, MyText Close FileOut Counter = Counter + 1 cmdExport.Caption = "Notes " & Counter 'Clear MyText so program will know a new record is starting MyText = "" Else 'If line read wasn't zero or one append the value MyText = MyText & vbCrLf & MyLine End If EndLoop: End If Loop Close FileIn MsgBox Counter & " memos saved to " & Left(Drive1.Drive, 2) & "/Notes/" 'Save the source directory and drive letter to a file for the next time. FileOut = FreeFile ChDir App.Path Open "memoparser.dat" For Output As FileOut Write #FileOut, txtSource, Drive1.Drive, chkTextExt.Value Close FileOut cmdExport.Caption = "Export" cmdExport.Enabled = True 'Exit the procedure Exit Sub ExportError: ' The user pressed the Cancel key. cmdExport.Caption = "Export" cmdExport.Enabled = True MsgBox "There was an error. " & Counter & " notes saved." Exit Sub End Sub Private Sub cmdOpen_Click() Dim Filter As String On Error GoTo OpenError 'Set up the Common Dialog Box to open a text file Filter = "All files (*.*)|*.*|" Filter = Filter + "Text Files (*.txt)|*.txt|" Filter = Filter + "Batch Files (*.bat)|*.bat" CommonDialog1.Filter = Filter 'Set the default File Type to Text Files (*.txt) CommonDialog1.FilterIndex = 2 'Display the Open dialog box. CommonDialog1.Action = 1 txtSource = CommonDialog1.FileName 'Exit the procedure Exit Sub OpenError: ' The user pressed the Cancel key. MsgBox "There was an error" Exit Sub End Sub Private Sub Form_Load() Dim FileIn, TextExt As Integer Dim FileName, DriveLetter As String 'See if Source and Drive info are saved from last time On Error GoTo NoInputFile FileIn = FreeFile Open "memoparser.dat" For Input As FileIn Input #FileIn, FileName, DriveLetter, TextExt txtSource = FileName Drive1.Drive = DriveLetter chkTextExt.Value = TextExt Close FileIn Exit Sub NoInputFile: Close FileIn 'MsgBox "No Input File" End Sub