Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.net 4.5, Help with reading text file from "Generic Printer" to file

Status
Not open for further replies.

leo57

Programmer
Oct 28, 2013
33
0
0
US
Company prints production tickets and then scans each Serial Number barcode into a software package. There are ~200 pages each day, so it takes time... I thought we could print them to a text file then I could grab out each Serial Number and save them to another file. however the word Serial Number is like so, a few letters on each line.
Ser
i
al

#
(as well as most other data in the file so finding anything is not so easy).

Can someone help me more efficient code, better code than try and look for "Ser" then "i" etc.

Code:
Using w As StreamWriter = File.AppendText(SpringFile)
                Me.ListBox1.Items.Add("Reading Print File")
                Dim objReader As New System.IO.StreamReader(FILE_NAME)
                Me.ListBox1.Items.Add("Writing Serial# file")
                Do While objReader.Peek() <> -1
                    Linedata = objReader.ReadLine()
                    If InStr(1, Linedata, "Ser") Then
                        'save to another text file
                        If InStr(1, Linedata, "Ser") Then
                            FindSerialNumberStart = InStr(1, Linedata, "Ser")

                            SerialNumber = Trim(Mid(Linedata, FindSerialNumberStart, 16))
                            w.WriteLine("*" & SerialNumber & "*")
                            w.WriteLine(SerialNumber)
                        End If

                       End if
                Loop

TIA


 
Maybe you could read the entire file into a temporary text file, stripping out all line breaks as you go. Then you should be able to find the words "Serial #" as a group and do whatever processing you need to do after that.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks, luckily the serial numbers all end in "00" so I looked for 02000 and then 00 to find what I needed.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top