I am having a problem with the code below. Firstly it tries to read the contents of the *hist file to an array. The *hist file should consist of ,,,, for a 100 lines, mostly with data inbetween the commas.
However after a powercut the file was filled with 200 nulls. This stopped the process from working, so i added a bit in the CATCH statement to delete the file.
Shortly later, the array is then written back to the *hist file (2nd procedure).
If i use a bad *hist file, it correctly deletes the file. But somehow, when i write back to the *hist file it remembers all the nulls and puts them in beforehand and i really cant see how. I even added another delete statement in the write procedure just to double check that the file is deleted, and streamwriter is set to overwrite any existing file anyway!
Any observations would be gratefully received.
Thanks.
However after a powercut the file was filled with 200 nulls. This stopped the process from working, so i added a bit in the CATCH statement to delete the file.
Shortly later, the array is then written back to the *hist file (2nd procedure).
If i use a bad *hist file, it correctly deletes the file. But somehow, when i write back to the *hist file it remembers all the nulls and puts them in beforehand and i really cant see how. I even added another delete statement in the write procedure just to double check that the file is deleted, and streamwriter is set to overwrite any existing file anyway!
Any observations would be gratefully received.
Thanks.
Code:
Read the ****.hist file to the array that fills the main flex grid
Public Sub ReadHistory()
Dim sr As New StreamReader(LogPath & ".hist") Names the file too read
Dim strJobLine As String = sr.ReadLine
Dim j As Integer = 0
Dim k As Integer = 1
Dim rx As New Regex(",")
Dim aryHistory As String()
Try
Do While Not (strJobLine Is Nothing)
aryHistory = rx.Split(strJobLine) splits the string every ,
putting them into, there own entry in an array
If k < 5 Or k > 95 Then MsgBox(Str(k)) test line
While j <= JMax
aryTenRecent(j, k) = aryHistory(j)
j += 1
End While
j = 0
k += 1 still needed to increment the bit where it actually fills the array
strJobLine = sr.ReadLine
Loop
sr.Close()
Catch
Try
sr.Close()
File.Delete(LogPath & ".hist")
Catch
MsgBox(Err.Description)
End Try
File.Delete(LogPath & ".hist")
LogOutput("Error with the ReadHistory Function. " + Err.Description)
MsgBox(Err.Description)
End Try
sr.Close()
End Sub
Code:
Write the contents to a file *****.hist from the array that fills the main flex grid
Public Sub WriteHistory()
Try
If File.Exists(LogPath & ".hist") Then _
File.Move(LogPath & ".hist", LogPath & "_old.hist")
Dim sw As New StreamWriter((LogPath & ".hist"), False) Names the file 2write
Dim j As Integer = 0
Dim k As Integer = 1
Dim strJobLine As String
This adds all the data for each line at a time to a file.
While k <= MainFlexSize Counts from 1 to mainflexsize (100)
While j <= JMax Counts from 0 to JMax (4)
strJobLine = strJobLine + aryTenRecent(j, k) + ","
j += 1
sw.WriteLine("#1 STRJOBLINE = " & strJobLine) testdata
End While
j = 0
k += 1
strJobLine = strJobLine.Remove(strJobLine.Length - 1, 1)
sw.WriteLine(strJobLine)
strJobLine = ""
End While
sw.WriteLine("-------------------Closed-------------------") testdata
sw.Close()
Catch
MsgBox(Err.Description)
LogOutput("Error with the WriteHistory Function. " + Err.Description)
End Try
End Sub