Private Sub mnuSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuSave.Click
Dim myStream As String
Dim saveFD As New SaveFileDialog()
Dim total As Integer
With saveFD
.Filter = "Text File (*.txt)|*.txt|(*.SRM)|*.SRM|(*.MIT)|*.MIT|All File(*.*)|*.*"
'.FilterIndex = 1
.RestoreDirectory = True
.InitialDirectory = "C:\My Documents"
End With
If saveFD.ShowDialog() = DialogResult.OK Then
myStream = saveFD.FileName()
'MsgBox(myStream) ' testting what it holds
Dim stBld As New System.Text.StringBuilder(TxtBox1.Text)
'MsgBox(stBld.Length()) ' Total no of characters in file
total = stBld.Length
stBld.Remove(0, 64)
stBld.Remove(stBld.Length - 3, 3)
' now loop through the string builder string and use insert command
'Dim sram(total) As String 'Declare an array tohold data
'Dim i As Integer ' Declare i for For loop
'Dim store As String 'Declare store to hold the arry processed data
Dim count As Integer = -2
Dim temCount As Integer = 0
'Dim hold As Integer = 0
Dim replace As String
Dim dtLog As String
'Dim totRec As Integer = 0
'hold = stBld
replace = TxtBox1.Text.Substring(0, 64)
dtLog = TxtBox1.Text.Substring(0, 2)
'Getting Start Time
Dim sTh As String = TxtBox1.Text.Substring(52, 2)
Dim sTm As String = TxtBox1.Text.Substring(54, 2)
Dim sTs As String = TxtBox1.Text.Substring(56, 2)
' Getting Start Date
Dim sDy As String = TxtBox1.Text.Substring(62, 2)
Dim sDm As String = TxtBox1.Text.Substring(60, 2)
Dim sDd As String = TxtBox1.Text.Substring(58, 2)
' Getting End Time
Dim eTh As String = TxtBox1.Text.Substring(40, 2)
Dim eTm As String = TxtBox1.Text.Substring(42, 2)
Dim ets As String = TxtBox1.Text.Substring(44, 2)
' Getting End Date
Dim eDy As String = TxtBox1.Text.Substring(50, 2)
Dim eDm As String = TxtBox1.Text.Substring(46, 2)
Dim eDd As String = TxtBox1.Text.Substring(48, 2)
'MsgBox(replace) ' Testing purpose only
Dim i As Integer
Dim hold() As Integer = New Integer(600) {}
Dim resultRecord As String
Dim lineNo As Integer
lineNo = 1
'hold = (numPortion.ToString("00000")) ' in this File each record starts with Time First then Date
' Increment each item in the string
While count <= stBld.Length
'MsgBox(count)
' counts 10 characters and insert break /Enter after ten characters
If temCount = 12 Then
stBld.Insert(count, vbCrLf)
'Rest temCount, so we start searching for next 10 characters
temCount = 0
' adding record no in an array
lineNo = lineNo + 1
hold(i) = lineNo
'MsgBox(hold(i))
End If
'MsgBox(temCount)
temCount = temCount + 1
count = count + 1
End While
' newly edited string
Dim mainString As String = stBld.ToString
Dim val As String
val = CmbBox.Text
'MsgBox(lineNo) ' Total No of Records
For j As Integer = 0 To (hold.Length - 1)
resultRecord = hold(j)
'MsgBox(resultRecord)
Next
'Now we write back the new string to the file
Dim objWriter As New System.IO.StreamWriter(myStream)
objWriter.Write("DataLog Report: ")
objWriter.WriteLine(dtLog)
objWriter.Write("SRT-")
objWriter.WriteLine(sTh + ":" + sTm + ":" + sTs + "-SRD-" + sDm + "/" + sDd + "/" + sDy)
objWriter.WriteLine("ERT-" + eTh + ":" + eTm + ":" + ets + "-ERD-" + eDm + "/" + eDd + "/" + eDy)
'objWriter.Write(replace)
objWriter.WriteLine("ENCT- " + lineNo.ToString("00000"))
'objWriter.WriteLine(hold)
objWriter.Write("TIP-")
objWriter.WriteLine(val)
'objWriter.WriteLine("-------------------")
objWriter.WriteLine()
objWriter.Write( mainString + "End of Report")
objWriter.Close()
End If
End Sub