Input File to read:
SAMPLE NO: 10S-02013
Moisture 10.1
DryMat 89.9
SAMPLE NO: 10S-02014
Moisture 10.1
DryMat 89.9
Output file should be
10S-02013|Moisture|10.1
10S-02013|DryMat|89.9
10S-02013|CrdPro|9.6
10S-02014|Moisture|10.1
10S-02014|DryMat|89.9
10S-02014|CrdPro|9.6
My program looks like this
I am not getting the right output I need, as whenever it reads a line, it looses my sample numeber. Any help will be appreciated.Thanks
SAMPLE NO: 10S-02013
Moisture 10.1
DryMat 89.9
SAMPLE NO: 10S-02014
Moisture 10.1
DryMat 89.9
Output file should be
10S-02013|Moisture|10.1
10S-02013|DryMat|89.9
10S-02013|CrdPro|9.6
10S-02014|Moisture|10.1
10S-02014|DryMat|89.9
10S-02014|CrdPro|9.6
My program looks like this
VB.NET:
Private Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Process.Click
Dim textFileName As String = "C:\NIR\niroutput.txt"
Dim textFile As IO.StreamWriter = IO.File.CreateText(textFileName) 'Final output file
Dim readFileName As String = "C:\NIR\nir.dat" 'Raw result file
Dim readFile As IO.StreamReader = IO.File.OpenText(readFileName)
Dim sampleNo As String
'Dim result As Decimal
Dim finalSampleNo As String
Dim testAndResult As String
' Dim sResults As String
Try
Do While (readFile.Peek <> -1)
sampleNo = readFile.ReadLine() 'Stores value of Sample Number
finalSampleNo = Trim((Mid(sampleNo, 12)))
testAndResult = readFile.ReadLine()
Do
If Mid(testAndResult, 1, 10) <> "SAMPLE NO:" Then
Dim ar As New ArrayList
ar.Add(finalSampleNo)
ar.Add(testAndResult)
Dim Str As String
Str = Join(ar.ToArray(), "|")
MsgBox(Str)
textFile.WriteLine(Str)
testAndResult = readFile.ReadLine()
End If
Loop Until (readFile.Peek <> -1)
Loop
' Return textFileName
Catch ex As Exception
Throw
' Return ""
MsgBox("Some Error")
Finally
If textFile IsNot Nothing Then
textFile.Close()
textFile = Nothing
End If
If readFile IsNot Nothing Then
readFile.Close()
readFile = Nothing
End If
End Try
End Sub
Last edited by a moderator: