You've helped me write a routine that merges and formats a text file when multiple files exist. The code is as follows:
If fileCount = 3 Then RestranName = getRestranName(0) RestranName2 = getRestranName(1) RestranName3 = getRestranName(2) Dim readtxt() As String = File.ReadAllLines(RestranName) 'Deleted the actual file. File.Delete(RestranName) 'Now time to read the array elements and save them in a file. For i As Integer = readtxt.GetLowerBound(0) To readtxt.GetUpperBound(0) - 4 'Appending the line to the text file My.Computer.FileSystem.WriteAllText(RestranName, readtxt(i), True) If i < readtxt.GetUpperBound(0) - 4 Then 'Appending a new line into the text file. My.Computer.FileSystem.WriteAllText(RestranName, vbCrLf, True) End If Next My.Computer.FileSystem.WriteAllText(RestranName, pageCode, True) Me.Cursor = Cursors.Default Dim readtxt2() As String = File.ReadAllLines(RestranName2) 'Deleted the actual file. File.Delete(RestranName2) 'Now time to read the array elements and save them in a file. For i As Integer = readtxt2.GetLowerBound(0) To readtxt2.GetUpperBound(0) - 4 'Appending the line to the text file My.Computer.FileSystem.WriteAllText(RestranName2, readtxt2(i), True) If i < readtxt2.GetUpperBound(0) - 4 Then 'Appending a new line into the text file. My.Computer.FileSystem.WriteAllText(RestranName2, vbCrLf, True) End If Next My.Computer.FileSystem.WriteAllText(RestranName2, pageCode, True) File.AppendAllText(RestranName, System.IO.File.ReadAllText(RestranName2)) File.AppendAllText(RestranName, File.ReadAllText(RestranName3)) File.Delete(RestranName2) File.Delete(RestranName3) End If ' setting the path name to save the converted file fileSave = "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\" & hotelFolder & "\Restran\" & propertyNo & "Restran.txt" ' Getting date extension to save the file in a history yesterday = Today.AddDays(-1) day = yesterday.Day.ToString month = yesterday.Month.ToString year = yesterday.Year.ToString year = year.Substring(2, 2) If yesterday.Day < 10 Then day = "0" & day End If If yesterday.Month < 10 Then month = "0" & month End If copyFile = "O:\Revenue Management\Centralized Revenue Management Service\CRMS Hotels\" & hotelFolder & "\Restran\Restran History\" & propertyNo & " Restran " & month & day & year & ".txt" ' This reads the text file for conversion txtLine = My.Computer.FileSystem.ReadAllText(RestranName) ' This begins to add the carriage returns in the appropriate places txtLine = Replace(txtLine, pageCode, vbCrLf & pageCode) txtLine = Replace(txtLine, vbLf, vbCrLf) txtLine = Replace(txtLine, vbCr & vbCr, vbCr) txtLine = Replace(txtLine, """", "") ' This writes the line to the file My.Computer.FileSystem.WriteAllText(fileSave, txtLine, False) System.IO.File.Copy(fileSave, copyFile) ' This deletes the old unconverted file System.IO.File.Delete(RestranName)
My latest issue has to do whether the program is actually stopped or not. During run-time, I'm getting a notice at the top of the user interface (next to the program name) that the program has stopped. This is only happening on days were there are multiple text files to merge.
Given what the code is doing on these days, it's taking several minutes to go through the routine. You probably need to know the routine is looping multiple times to capture the next property number in the sequence. Generally after the 1st or second property (truthfully I can't actually tell when it's saying it's stopped), is when I get the notice that it's stopped. But then again, has it really? I say that as it seems to be going through the routine but I never get the message that says it's completed the tasks.
I'm sure someone has seen this before. Any thoughts on how to make sure everything runs correctly and completely? FYI... it runs perfectly and very quickly when there is only one text file to format in each property folder.
Thanks for the help.