Text file :
110300534D0169202000000000000002030000101200291102101231371005101332231005133225100513333110051339211005133942100513402910051340581005134130100513415310051341551005134221100513433410051351211005154241100515442710051546581005155032100516013110051601331005161032100518033710051215211006145621100814562310081458541008150021100815002310081500391008150053100815005510081501151008150137100815014010081501571008150241100815024210081503281008150348100815034910081504291008150431100815044810081505061008150508100815052410081505371008150539100815055310081506071008150609100815062510081506411008150643100815065910081507321008150749100815075110081508331008150858100815090010081509261008150944100815094610081509581008151032100815104810081510
Requirement :
These are first 64 characters DataLog Report: 11 SRT-12:31:37-SRD-05/10/10 ERT-12:00:29-ERD-11/02/10 ENCT- 00362 (Total no of record) TIP- N00001T133223D1005 T for Time D for Date N00002T133225D1005 1333311005 1339211005 1339421005 1340291005 1340581005 1341301005 1341531005 1341551005 1342211005 1343341005 1351211005 here is my code file already opend , i press save menu option and this code create new file, convert it into records but unable to insert Record no as N00001 ...... n T D [code] 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 [/code]
DataLog Report: 11
SRT-12:31:37-SRD-05/10/10
ERT-12:00:29-ERD-11/02/10
ENCT- 00362 (Total no of record)
TIP-
N00001T133223D1005 T for Time D for Date
N00002T133225D1005
1333311005
1339211005
1339421005
1340291005
1340581005
1341301005
1341531005
1341551005
1342211005
1343341005
1351211005
here is my code
file already opend , i press save menu option and this code create new file, convert it into records but unable to insert Record no as N00001 ...... n T D
[code] 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
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 Sub
[/code]