|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Organize and Print CSV datamake it happen. I have a CSV file shows up in a directory that has 4 fields that need to be printed on labels. Each line of the CSV looks something like this: AcctNo, Name, junk, junk, Address, junk, PhoneNo I need to read each line of the CSV and print them to Avery Label stock (30 labels per sheet, 3 columns, 10 rows). I also need them to pull from a specific tray on the printer. The result should look something like this: Jim Smith Mary Smith John Doe 123 any street 50 First st 12 Maple ST 8542115 12345678 9858574 555-555-1212 555-555-1111 555-555-2222 I am thinking the steps are something like this: 1. Watch the directory for a CSV file 2. Use StreamReader to read each line of the CSV 3. Drop fields 3,4 and 6 (the Junk fields) 4. Organize fields to this order: Name, address, AcctNo, PhoneNo 5. Select the appropriate tray of a specific printer 6. Print the records in 3 rows, 10 columns. I know Word/Excel can read a CSV, do a mailmerge and output the labels but my customer is interested in a VB.net solution. Is this way too complicated? Any ideas on how to get started? Thanks in advance. I would recommend the Word/Excel combo. If your customer insists on
reinventing the wheel, charge him double! T Jchick wrote: Show quoteHide quote >Boy, this should be a simple bit of code but I can't figure out how to >make it happen. > >I have a CSV file shows up in a directory that has 4 fields that need >to be printed on labels. Each line of the CSV looks something like >this: > >AcctNo, Name, junk, junk, Address, junk, PhoneNo > >I need to read each line of the CSV and print them to Avery Label stock >(30 labels per sheet, 3 columns, 10 rows). I also need them to pull >from a specific tray on the printer. > >The result should look something like this: > >Jim Smith Mary Smith John Doe >123 any street 50 First st 12 Maple ST >8542115 12345678 9858574 >555-555-1212 555-555-1111 555-555-2222 > >I am thinking the steps are something like this: >1. Watch the directory for a CSV file >2. Use StreamReader to read each line of the CSV >3. Drop fields 3,4 and 6 (the Junk fields) >4. Organize fields to this order: Name, address, AcctNo, PhoneNo >5. Select the appropriate tray of a specific printer >6. Print the records in 3 rows, 10 columns. > > >I know Word/Excel can read a CSV, do a mailmerge and output the labels >but my customer is interested in a VB.net solution. > >Is this way too complicated? Any ideas on how to get started? > >Thanks in advance. > > > Hello Jchick,
This is relatively straight forward with ADO.Net. Use a OdbcConnection/Command or OleDbConnection/Command with the appropriate connection string (see connectionstrings.com). Other than that, your method looks fine. -Boo Show quoteHide quote > Boy, this should be a simple bit of code but I can't figure out how to > make it happen. > > I have a CSV file shows up in a directory that has 4 fields that need > to be printed on labels. Each line of the CSV looks something like > this: > > AcctNo, Name, junk, junk, Address, junk, PhoneNo > > I need to read each line of the CSV and print them to Avery Label > stock (30 labels per sheet, 3 columns, 10 rows). I also need them to > pull from a specific tray on the printer. > > The result should look something like this: > > Jim Smith Mary Smith John Doe > 123 any street 50 First st 12 Maple ST > 8542115 12345678 9858574 > 555-555-1212 555-555-1111 555-555-2222 > I am thinking the steps are something like this: > 1. Watch the directory for a CSV file > 2. Use StreamReader to read each line of the CSV > 3. Drop fields 3,4 and 6 (the Junk fields) > 4. Organize fields to this order: Name, address, AcctNo, PhoneNo > 5. Select the appropriate tray of a specific printer > 6. Print the records in 3 rows, 10 columns. > I know Word/Excel can read a CSV, do a mailmerge and output the labels > but my customer is interested in a VB.net solution. > > Is this way too complicated? Any ideas on how to get started? > > Thanks in advance. > Boo,
I don't see where OleDB or ODBC can help the OP? Can you explain that further, I would keep it with his own procedure. Cor Show quoteHide quote "GhostInAK" <ghosti***@gmail.com> schreef in bericht news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... > Hello Jchick, > > This is relatively straight forward with ADO.Net. Use a > OdbcConnection/Command or OleDbConnection/Command with the appropriate > connection string (see connectionstrings.com). > Other than that, your method looks fine. > > -Boo > >> Boy, this should be a simple bit of code but I can't figure out how to >> make it happen. >> >> I have a CSV file shows up in a directory that has 4 fields that need >> to be printed on labels. Each line of the CSV looks something like >> this: >> >> AcctNo, Name, junk, junk, Address, junk, PhoneNo >> >> I need to read each line of the CSV and print them to Avery Label >> stock (30 labels per sheet, 3 columns, 10 rows). I also need them to >> pull from a specific tray on the printer. >> >> The result should look something like this: >> >> Jim Smith Mary Smith John Doe >> 123 any street 50 First st 12 Maple ST >> 8542115 12345678 9858574 >> 555-555-1212 555-555-1111 555-555-2222 >> I am thinking the steps are something like this: >> 1. Watch the directory for a CSV file >> 2. Use StreamReader to read each line of the CSV >> 3. Drop fields 3,4 and 6 (the Junk fields) >> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >> 5. Select the appropriate tray of a specific printer >> 6. Print the records in 3 rows, 10 columns. >> I know Word/Excel can read a CSV, do a mailmerge and output the labels >> but my customer is interested in a VB.net solution. >> >> Is this way too complicated? Any ideas on how to get started? >> >> Thanks in advance. >> > > I'm not familiar with the ADO stuff anyway. I'm a noob. After thinking
about it, it may be better to simply install Word (use that for the 'engine') and write macros or VB to do the process. What do ya'll think? Hello Cor Ligthert [MVP],
ADO is the way to go when accessing CSV files. Field values can be quoted or not.. which makes parsing my hand difficult, but not impossible. ADO will simply be easier and faster than rolling your own CSV parser, especially for a newbie. -Boo Show quoteHide quote > Boo, > > I don't see where OleDB or ODBC can help the OP? > > Can you explain that further, I would keep it with his own procedure. > > Cor > > "GhostInAK" <ghosti***@gmail.com> schreef in bericht > news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... > >> Hello Jchick, >> >> This is relatively straight forward with ADO.Net. Use a >> OdbcConnection/Command or OleDbConnection/Command with the >> appropriate >> connection string (see connectionstrings.com). >> Other than that, your method looks fine. >> -Boo >> >>> Boy, this should be a simple bit of code but I can't figure out how >>> to make it happen. >>> >>> I have a CSV file shows up in a directory that has 4 fields that >>> need to be printed on labels. Each line of the CSV looks something >>> like this: >>> >>> AcctNo, Name, junk, junk, Address, junk, PhoneNo >>> >>> I need to read each line of the CSV and print them to Avery Label >>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them to >>> pull from a specific tray on the printer. >>> >>> The result should look something like this: >>> >>> Jim Smith Mary Smith John Doe >>> 123 any street 50 First st 12 Maple ST >>> 8542115 12345678 9858574 >>> 555-555-1212 555-555-1111 555-555-2222 >>> I am thinking the steps are something like this: >>> 1. Watch the directory for a CSV file >>> 2. Use StreamReader to read each line of the CSV >>> 3. Drop fields 3,4 and 6 (the Junk fields) >>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >>> 5. Select the appropriate tray of a specific printer >>> 6. Print the records in 3 rows, 10 columns. >>> I know Word/Excel can read a CSV, do a mailmerge and output the >>> labels >>> but my customer is interested in a VB.net solution. >>> Is this way too complicated? Any ideas on how to get started? >>> >>> Thanks in advance. >>> Boo,
Why? A classic approach needs only a classic loop whatever that is (For Do While), which can be done even direct in the reading part. The OP shows that he/she is a newbie in Net not in programming. That you and I probably will direct do it with OleDb and a datatable, does not mean in my eyes that what we do is the most efficient or the best method for this problem. Just my thought, Cor Show quoteHide quote "GhostInAK" <ghosti***@gmail.com> schreef in bericht news:c71747b42d6eb8c895065dfbe98c@news.microsoft.com... > Hello Cor Ligthert [MVP], > > ADO is the way to go when accessing CSV files. Field values can be quoted > or not.. which makes parsing my hand difficult, but not impossible. ADO > will simply be easier and faster than rolling your own CSV parser, > especially for a newbie. > > -Boo > >> Boo, >> >> I don't see where OleDB or ODBC can help the OP? >> >> Can you explain that further, I would keep it with his own procedure. >> >> Cor >> >> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >> news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... >> >>> Hello Jchick, >>> >>> This is relatively straight forward with ADO.Net. Use a >>> OdbcConnection/Command or OleDbConnection/Command with the >>> appropriate >>> connection string (see connectionstrings.com). >>> Other than that, your method looks fine. >>> -Boo >>> >>>> Boy, this should be a simple bit of code but I can't figure out how >>>> to make it happen. >>>> >>>> I have a CSV file shows up in a directory that has 4 fields that >>>> need to be printed on labels. Each line of the CSV looks something >>>> like this: >>>> >>>> AcctNo, Name, junk, junk, Address, junk, PhoneNo >>>> >>>> I need to read each line of the CSV and print them to Avery Label >>>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them to >>>> pull from a specific tray on the printer. >>>> >>>> The result should look something like this: >>>> >>>> Jim Smith Mary Smith John Doe >>>> 123 any street 50 First st 12 Maple ST >>>> 8542115 12345678 9858574 >>>> 555-555-1212 555-555-1111 555-555-2222 >>>> I am thinking the steps are something like this: >>>> 1. Watch the directory for a CSV file >>>> 2. Use StreamReader to read each line of the CSV >>>> 3. Drop fields 3,4 and 6 (the Junk fields) >>>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >>>> 5. Select the appropriate tray of a specific printer >>>> 6. Print the records in 3 rows, 10 columns. >>>> I know Word/Excel can read a CSV, do a mailmerge and output the >>>> labels >>>> but my customer is interested in a VB.net solution. >>>> Is this way too complicated? Any ideas on how to get started? >>>> >>>> Thanks in advance. >>>> > > OK, how about I simplify this. What about simply reading a CSV and
printing each record to a label? Any bits of code available for that? Cor Ligthert [MVP] wrote: Show quoteHide quote > Boo, > > Why? A classic approach needs only a classic loop whatever that is (For Do > While), which can be done even direct in the reading part. The OP shows that > he/she is a newbie in Net not in programming. > > That you and I probably will direct do it with OleDb and a datatable, does > not mean in my eyes that what we do is the most efficient or the best method > for this problem. > > Just my thought, > > Cor > > "GhostInAK" <ghosti***@gmail.com> schreef in bericht > news:c71747b42d6eb8c895065dfbe98c@news.microsoft.com... > > Hello Cor Ligthert [MVP], > > > > ADO is the way to go when accessing CSV files. Field values can be quoted > > or not.. which makes parsing my hand difficult, but not impossible. ADO > > will simply be easier and faster than rolling your own CSV parser, > > especially for a newbie. > > > > -Boo > > > >> Boo, > >> > >> I don't see where OleDB or ODBC can help the OP? > >> > >> Can you explain that further, I would keep it with his own procedure. > >> > >> Cor > >> > >> "GhostInAK" <ghosti***@gmail.com> schreef in bericht > >> news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... > >> > >>> Hello Jchick, > >>> > >>> This is relatively straight forward with ADO.Net. Use a > >>> OdbcConnection/Command or OleDbConnection/Command with the > >>> appropriate > >>> connection string (see connectionstrings.com). > >>> Other than that, your method looks fine. > >>> -Boo > >>> > >>>> Boy, this should be a simple bit of code but I can't figure out how > >>>> to make it happen. > >>>> > >>>> I have a CSV file shows up in a directory that has 4 fields that > >>>> need to be printed on labels. Each line of the CSV looks something > >>>> like this: > >>>> > >>>> AcctNo, Name, junk, junk, Address, junk, PhoneNo > >>>> > >>>> I need to read each line of the CSV and print them to Avery Label > >>>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them to > >>>> pull from a specific tray on the printer. > >>>> > >>>> The result should look something like this: > >>>> > >>>> Jim Smith Mary Smith John Doe > >>>> 123 any street 50 First st 12 Maple ST > >>>> 8542115 12345678 9858574 > >>>> 555-555-1212 555-555-1111 555-555-2222 > >>>> I am thinking the steps are something like this: > >>>> 1. Watch the directory for a CSV file > >>>> 2. Use StreamReader to read each line of the CSV > >>>> 3. Drop fields 3,4 and 6 (the Junk fields) > >>>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo > >>>> 5. Select the appropriate tray of a specific printer > >>>> 6. Print the records in 3 rows, 10 columns. > >>>> I know Word/Excel can read a CSV, do a mailmerge and output the > >>>> labels > >>>> but my customer is interested in a VB.net solution. > >>>> Is this way too complicated? Any ideas on how to get started? > >>>> > >>>> Thanks in advance. > >>>> > > > > Jchick,
This should be so simple that if you cannot make this, than try to find somebody who can make this for you. I would be shame myself to put this kind of simple things on Internet or it should be a part of a much wider sample. Cor Show quoteHide quote "Jchick" <jchicker***@gmail.com> schreef in bericht news:1156559116.846264.178270@p79g2000cwp.googlegroups.com... > OK, how about I simplify this. What about simply reading a CSV and > printing each record to a label? Any bits of code available for that? > > > > Cor Ligthert [MVP] wrote: >> Boo, >> >> Why? A classic approach needs only a classic loop whatever that is (For >> Do >> While), which can be done even direct in the reading part. The OP shows >> that >> he/she is a newbie in Net not in programming. >> >> That you and I probably will direct do it with OleDb and a datatable, >> does >> not mean in my eyes that what we do is the most efficient or the best >> method >> for this problem. >> >> Just my thought, >> >> Cor >> >> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >> news:c71747b42d6eb8c895065dfbe98c@news.microsoft.com... >> > Hello Cor Ligthert [MVP], >> > >> > ADO is the way to go when accessing CSV files. Field values can be >> > quoted >> > or not.. which makes parsing my hand difficult, but not impossible. >> > ADO >> > will simply be easier and faster than rolling your own CSV parser, >> > especially for a newbie. >> > >> > -Boo >> > >> >> Boo, >> >> >> >> I don't see where OleDB or ODBC can help the OP? >> >> >> >> Can you explain that further, I would keep it with his own procedure. >> >> >> >> Cor >> >> >> >> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >> >> news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... >> >> >> >>> Hello Jchick, >> >>> >> >>> This is relatively straight forward with ADO.Net. Use a >> >>> OdbcConnection/Command or OleDbConnection/Command with the >> >>> appropriate >> >>> connection string (see connectionstrings.com). >> >>> Other than that, your method looks fine. >> >>> -Boo >> >>> >> >>>> Boy, this should be a simple bit of code but I can't figure out how >> >>>> to make it happen. >> >>>> >> >>>> I have a CSV file shows up in a directory that has 4 fields that >> >>>> need to be printed on labels. Each line of the CSV looks something >> >>>> like this: >> >>>> >> >>>> AcctNo, Name, junk, junk, Address, junk, PhoneNo >> >>>> >> >>>> I need to read each line of the CSV and print them to Avery Label >> >>>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them to >> >>>> pull from a specific tray on the printer. >> >>>> >> >>>> The result should look something like this: >> >>>> >> >>>> Jim Smith Mary Smith John Doe >> >>>> 123 any street 50 First st 12 Maple ST >> >>>> 8542115 12345678 9858574 >> >>>> 555-555-1212 555-555-1111 555-555-2222 >> >>>> I am thinking the steps are something like this: >> >>>> 1. Watch the directory for a CSV file >> >>>> 2. Use StreamReader to read each line of the CSV >> >>>> 3. Drop fields 3,4 and 6 (the Junk fields) >> >>>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >> >>>> 5. Select the appropriate tray of a specific printer >> >>>> 6. Print the records in 3 rows, 10 columns. >> >>>> I know Word/Excel can read a CSV, do a mailmerge and output the >> >>>> labels >> >>>> but my customer is interested in a VB.net solution. >> >>>> Is this way too complicated? Any ideas on how to get started? >> >>>> >> >>>> Thanks in advance. >> >>>> >> > >> > > Hello Cor Ligthert [MVP],
The issue is readability and intent. Some crack-ass loop with data reads and string splits and all manner of nastiness THAT IS COMPLETELY UNNEEDED muddles the readability and confuses the intent. Was this chunk of code supposed to demonstrate the ability to parse a CSV file? or was this chunk of code supposed to demonstrate reading a CSV file and manipulating the data? There are times when re-inventing the wheel is acceptable and at time nessecary, especialy if the existing wheel is horribly broken. However, ADO.NET is not horribly broken, and it is absolutely the right tool for reading CSV files (writing may be a different matter). -Boo Show quoteHide quote > Boo, > > Why? A classic approach needs only a classic loop whatever that is > (For Do While), which can be done even direct in the reading part. The > OP shows that he/she is a newbie in Net not in programming. > > That you and I probably will direct do it with OleDb and a datatable, > does not mean in my eyes that what we do is the most efficient or the > best method for this problem. > > Just my thought, > > Cor > > "GhostInAK" <ghosti***@gmail.com> schreef in bericht > news:c71747b42d6eb8c895065dfbe98c@news.microsoft.com... > >> Hello Cor Ligthert [MVP], >> >> ADO is the way to go when accessing CSV files. Field values can be >> quoted or not.. which makes parsing my hand difficult, but not >> impossible. ADO will simply be easier and faster than rolling your >> own CSV parser, especially for a newbie. >> >> -Boo >> >>> Boo, >>> >>> I don't see where OleDB or ODBC can help the OP? >>> >>> Can you explain that further, I would keep it with his own >>> procedure. >>> >>> Cor >>> >>> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >>> news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... >>> >>>> Hello Jchick, >>>> >>>> This is relatively straight forward with ADO.Net. Use a >>>> OdbcConnection/Command or OleDbConnection/Command with the >>>> appropriate >>>> connection string (see connectionstrings.com). >>>> Other than that, your method looks fine. >>>> -Boo >>>>> Boy, this should be a simple bit of code but I can't figure out >>>>> how to make it happen. >>>>> >>>>> I have a CSV file shows up in a directory that has 4 fields that >>>>> need to be printed on labels. Each line of the CSV looks something >>>>> like this: >>>>> >>>>> AcctNo, Name, junk, junk, Address, junk, PhoneNo >>>>> >>>>> I need to read each line of the CSV and print them to Avery Label >>>>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them >>>>> to pull from a specific tray on the printer. >>>>> >>>>> The result should look something like this: >>>>> >>>>> Jim Smith Mary Smith John Doe >>>>> 123 any street 50 First st 12 Maple ST >>>>> 8542115 12345678 9858574 >>>>> 555-555-1212 555-555-1111 555-555-2222 >>>>> I am thinking the steps are something like this: >>>>> 1. Watch the directory for a CSV file >>>>> 2. Use StreamReader to read each line of the CSV >>>>> 3. Drop fields 3,4 and 6 (the Junk fields) >>>>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >>>>> 5. Select the appropriate tray of a specific printer >>>>> 6. Print the records in 3 rows, 10 columns. >>>>> I know Word/Excel can read a CSV, do a mailmerge and output the >>>>> labels >>>>> but my customer is interested in a VB.net solution. >>>>> Is this way too complicated? Any ideas on how to get started? >>>>> Thanks in advance. >>>>> Boo,
Did you look at the sample ShaneO has given, I think that it shows a quiet better way than using OleDB. Although I repeat, OleDB would be for me the first choice if it was for myself. But from the first time I came on this board, I have showed that I like very much datatables. Cor Show quoteHide quote "GhostInAK" <ghosti***@gmail.com> schreef in bericht news:c71747b42ddb38c898126e49bb16@news.microsoft.com... > Hello Cor Ligthert [MVP], > > The issue is readability and intent. Some crack-ass loop with data reads > and string splits and all manner of nastiness THAT IS COMPLETELY UNNEEDED > muddles the readability and confuses the intent. Was this chunk of code > supposed to demonstrate the ability to parse a CSV file? or was this chunk > of code supposed to demonstrate reading a CSV file and manipulating the > data? > > There are times when re-inventing the wheel is acceptable and at time > nessecary, especialy if the existing wheel is horribly broken. However, > ADO.NET is not horribly broken, and it is absolutely the right tool for > reading CSV files (writing may be a different matter). > > -Boo > >> Boo, >> >> Why? A classic approach needs only a classic loop whatever that is >> (For Do While), which can be done even direct in the reading part. The >> OP shows that he/she is a newbie in Net not in programming. >> >> That you and I probably will direct do it with OleDb and a datatable, >> does not mean in my eyes that what we do is the most efficient or the >> best method for this problem. >> >> Just my thought, >> >> Cor >> >> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >> news:c71747b42d6eb8c895065dfbe98c@news.microsoft.com... >> >>> Hello Cor Ligthert [MVP], >>> >>> ADO is the way to go when accessing CSV files. Field values can be >>> quoted or not.. which makes parsing my hand difficult, but not >>> impossible. ADO will simply be easier and faster than rolling your >>> own CSV parser, especially for a newbie. >>> >>> -Boo >>> >>>> Boo, >>>> >>>> I don't see where OleDB or ODBC can help the OP? >>>> >>>> Can you explain that further, I would keep it with his own >>>> procedure. >>>> >>>> Cor >>>> >>>> "GhostInAK" <ghosti***@gmail.com> schreef in bericht >>>> news:c71747b42d1f88c893691dbcbdf4@news.microsoft.com... >>>> >>>>> Hello Jchick, >>>>> >>>>> This is relatively straight forward with ADO.Net. Use a >>>>> OdbcConnection/Command or OleDbConnection/Command with the >>>>> appropriate >>>>> connection string (see connectionstrings.com). >>>>> Other than that, your method looks fine. >>>>> -Boo >>>>>> Boy, this should be a simple bit of code but I can't figure out >>>>>> how to make it happen. >>>>>> >>>>>> I have a CSV file shows up in a directory that has 4 fields that >>>>>> need to be printed on labels. Each line of the CSV looks something >>>>>> like this: >>>>>> >>>>>> AcctNo, Name, junk, junk, Address, junk, PhoneNo >>>>>> >>>>>> I need to read each line of the CSV and print them to Avery Label >>>>>> stock (30 labels per sheet, 3 columns, 10 rows). I also need them >>>>>> to pull from a specific tray on the printer. >>>>>> >>>>>> The result should look something like this: >>>>>> >>>>>> Jim Smith Mary Smith John Doe >>>>>> 123 any street 50 First st 12 Maple ST >>>>>> 8542115 12345678 9858574 >>>>>> 555-555-1212 555-555-1111 555-555-2222 >>>>>> I am thinking the steps are something like this: >>>>>> 1. Watch the directory for a CSV file >>>>>> 2. Use StreamReader to read each line of the CSV >>>>>> 3. Drop fields 3,4 and 6 (the Junk fields) >>>>>> 4. Organize fields to this order: Name, address, AcctNo, PhoneNo >>>>>> 5. Select the appropriate tray of a specific printer >>>>>> 6. Print the records in 3 rows, 10 columns. >>>>>> I know Word/Excel can read a CSV, do a mailmerge and output the >>>>>> labels >>>>>> but my customer is interested in a VB.net solution. >>>>>> Is this way too complicated? Any ideas on how to get started? >>>>>> Thanks in advance. >>>>>> > > Jchick wrote:
Show quoteHide quote > Boy, this should be a simple bit of code but I can't figure out how to I borrowed from the MS Help and was able to knock-up the following in a > make it happen. > > I have a CSV file shows up in a directory that has 4 fields that need > to be printed on labels. Each line of the CSV looks something like > this: > > AcctNo, Name, junk, junk, Address, junk, PhoneNo > > I need to read each line of the CSV and print them to Avery Label stock > (30 labels per sheet, 3 columns, 10 rows). I also need them to pull > from a specific tray on the printer. > > The result should look something like this: > > Jim Smith Mary Smith John Doe > 123 any street 50 First st 12 Maple ST > 8542115 12345678 9858574 > 555-555-1212 555-555-1111 555-555-2222 > > I am thinking the steps are something like this: > 1. Watch the directory for a CSV file > 2. Use StreamReader to read each line of the CSV > 3. Drop fields 3,4 and 6 (the Junk fields) > 4. Organize fields to this order: Name, address, AcctNo, PhoneNo > 5. Select the appropriate tray of a specific printer > 6. Print the records in 3 rows, 10 columns. > > > I know Word/Excel can read a CSV, do a mailmerge and output the labels > but my customer is interested in a VB.net solution. > > Is this way too complicated? Any ideas on how to get started? > > Thanks in advance. > couple of minutes. If your CSV is as you wrote then this works perfectly (watch for wrapping!) - Dim sString As String Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim sCurrentRow As String() While Not MyReader.EndOfData sString = "" Try sCurrentRow = MyReader.ReadFields() sString = sCurrentRow(1) & vbCrLf & sCurrentRow(4)_ & vbCrLf & sCurrentRow(6) & vbCrLf & sCurrentRow(0) MsgBox(sString) Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While End Using I'm not arguing that this is the "Best" solution, but it does work. Hope this helps. ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. ShaneO, that's awesome. Thanks for taking the time to do that. It works
perfectly and gives me something to work with. Sorry it was too simple folks! J ShaneO wrote: Show quoteHide quote > Jchick wrote: > > Boy, this should be a simple bit of code but I can't figure out how to > > make it happen. > > > > I have a CSV file shows up in a directory that has 4 fields that need > > to be printed on labels. Each line of the CSV looks something like > > this: > > > > AcctNo, Name, junk, junk, Address, junk, PhoneNo > > > > I need to read each line of the CSV and print them to Avery Label stock > > (30 labels per sheet, 3 columns, 10 rows). I also need them to pull > > from a specific tray on the printer. > > > > The result should look something like this: > > > > Jim Smith Mary Smith John Doe > > 123 any street 50 First st 12 Maple ST > > 8542115 12345678 9858574 > > 555-555-1212 555-555-1111 555-555-2222 > > > > I am thinking the steps are something like this: > > 1. Watch the directory for a CSV file > > 2. Use StreamReader to read each line of the CSV > > 3. Drop fields 3,4 and 6 (the Junk fields) > > 4. Organize fields to this order: Name, address, AcctNo, PhoneNo > > 5. Select the appropriate tray of a specific printer > > 6. Print the records in 3 rows, 10 columns. > > > > > > I know Word/Excel can read a CSV, do a mailmerge and output the labels > > but my customer is interested in a VB.net solution. > > > > Is this way too complicated? Any ideas on how to get started? > > > > Thanks in advance. > > > > I borrowed from the MS Help and was able to knock-up the following in a > couple of minutes. If your CSV is as you wrote then this works > perfectly (watch for wrapping!) - > > Dim sString As String > Using MyReader As New > Microsoft.VisualBasic.FileIO.TextFieldParser("C:\test.csv") > MyReader.TextFieldType = FileIO.FieldType.Delimited > MyReader.SetDelimiters(",") > Dim sCurrentRow As String() > While Not MyReader.EndOfData > sString = "" > Try > sCurrentRow = MyReader.ReadFields() > sString = sCurrentRow(1) & vbCrLf & sCurrentRow(4)_ > & vbCrLf & sCurrentRow(6) & vbCrLf & sCurrentRow(0) > MsgBox(sString) > Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException > MsgBox("Line " & ex.Message & "is not valid and will be skipped.") > End Try > End While > End Using > > I'm not arguing that this is the "Best" solution, but it does work. > > Hope this helps. > > ShaneO > > There are 10 kinds of people - Those who understand Binary and those who > don't.
Handling refreshes from browser
Multiple Table DataSet Change box color on checkbox control Application Crashes on Test PC Automated File Copying count occurrences of string within a string how to display a label only a while? How to check base class type of 'open' generic class? (inheritance check) Has Dataset Changed? Re: MS Access Reports and VB.NET Program |
|||||||||||||||||||||||