Hi Everyone,
Most recently, I've been working on a small project to sort through multiple text files which have all the same strings. Basically, I am looking to sort through and create a text delimited file for future use. The below script is what I have come up with so far, and have tried several "For Loops" but found that I was lot worse off than working with the "Do";
Dim dlgOpen As New OpenFileDialog()
dlgOpen.CheckFileExists = True
dlgOpen.DefaultExt = "txt"
dlgOpen.InitialDirectory = "C:\DocBase"
dlgOpen.Multiselect = False
Dim strDocumentName As String = ""
Dim strDocumentNumber As String = ""
Dim strDocumentWorkOrder As String = ""
If dlgOpen.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
Using readDocFile As New IO.StreamReader(dlgOpen.FileName)
Dim strCurrentLineOne As String = ""
Dim strCurrentLineTwo As String = ""
Dim strCurrentlineThree As String = ""
Do
strCurrentLineOne = readDocFile.ReadLine
If strCurrentLineOne.Contains("Document Name:") Then
strDocumentName = strCurrentLineOne.Substring(14)
Exit Do
End If
Loop Until strCurrentLineOne Is Nothing
Do
strCurrentLineTwo = readDocFile.ReadLine
If strCurrentLineTwo.Contains("Document Number:") Then
strDocumentNumber = strCurrentLineTwo.Substring(16)
Exit Do
End If
Loop Until strCurrentLineTwo Is Nothing
Do
strCurrentlineThree = readDocFile.ReadLine
If strCurrentlineThree.Contains("Document Work Order:") Then
strDocumentWorkOrder = strCurrentlineThree.Substring(20)
Exit Do
End If
Loop Until strCurrentlineThree Is Nothing
End Using 'readDocFile closes and disposes
TextBox1.Text = strDocumentName & ", " & strDocumentNumber & ", " & strDocumentWorkOrder
Basically, what this little script does, or should do, is loop through the text file (shown below) once opened through the "OpenFileDialog", and looks for "Document Name:", "Document Number:" and "Document Work Order:"; (There are thousands of these text files, some large and some small, but all with the same String Scheme).
Document Name:Document 1
Document Number:1234567
Document Work Order:38VZ-001
Document Name:Document 2
Document Number:3456789-123
Document Work Order:38VZ-002
Document Name:Document 3
Document Number:456912-123-12V1
Document Work Order:38VZ-003
Document Name:Document 4
Document Number:891234
Document Work Order:38VZ-004
In return, after the substrings remove the requested chars, I am expecting that the script would output these lines and sort them to TextBox1 just like so?:
Document 1, 1234567, 38VZ-001
Document 2, 3456789-123, 38VZ-002
Document 3, 456912-123-12V1, 38VZ-003
Document 4, 891234, 38VZ-004
The script does work, but the problem is that it only returns one line to TextBox1 (Multiline TextBox)as shown here;
Document 1, 1234567, 38VZ-001
I am more than certain that something I've done (or not) is, well, not right. And more certain than not, the issue remains between the chair and the keyboard on this one...
Would anyone have any thoughts, scripts, and/or samples that can point me in the right direction?
Happy coding everyone!
Thanks!
VNexus