Writing To A Text File
-
Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance
-
Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance
rowdykuttan wrote:
when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1
Then check the lenth first, and if it is too large then truncate it. Or increase the space in the format.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
rowdykuttan wrote:
when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1
Then check the lenth first, and if it is too large then truncate it. Or increase the space in the format.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY, is there any way i can specify X & Y positions in text file or printer
-
Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance
If PITEMNAME's length is > 45, it is going to push everything over. You could truncate at 45 or you look at all the PITEMNAME values (assuming you are looping and trying to dump out data in columns) and set the pad accordingly rather than specifying 45. If you are limited to your width and 45 is max, truncating is what I'd do, probably. Good Luck!
It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?
-
am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY, is there any way i can specify X & Y positions in text file or printer
rowdykuttan wrote:
am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY
You might like to specify that next time. It helps people understand your problem. If you have a fixed external constraint like the size of preprinted paper then you have to truncate the information printed. Lop off a few characters. You'll find an appropriate method on the
string
class. Subseq, Substring or some such thing.rowdykuttan wrote:
is there any way i can specify X & Y positions in text file
If the file is formated as fixed length lines then you can calculate any XY position in the file and
Seek
to it.(Y*LineLength) + X
LineLength
includes the two character line feed and carriage return characters. It also assumes a fixed 8-bit character encoding.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance
Are you looking to do something like this?
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison
March 4, 1841
10 John Tyler April 4, 1841 -
Are you looking to do something like this?
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison
March 4, 1841
10 John Tyler April 4, 1841yes exactly but for William H. Harrison its comming in next line, i have left space for it like 1 George Washington April 30, 1789 2 John Adams March 4, 1797 3 Thomas Jefferson March 4, 1801 4 James Madison March 4, 1809 5 James Monroe March 4, 1817 6 John Quincy Adams March 4, 1825 7 Andrew Jackson March 4, 1829 8 Martin Van Buren March 4, 1837 9 William H. Harrison March 4, 1841 10 John Tyler April 4, 1841 i have enough space like this after name, plz tell me how to do it
-
yes exactly but for William H. Harrison its comming in next line, i have left space for it like 1 George Washington April 30, 1789 2 John Adams March 4, 1797 3 Thomas Jefferson March 4, 1801 4 James Madison March 4, 1809 5 James Monroe March 4, 1817 6 John Quincy Adams March 4, 1825 7 Andrew Jackson March 4, 1829 8 Martin Van Buren March 4, 1837 9 William H. Harrison March 4, 1841 10 John Tyler April 4, 1841 i have enough space like this after name, plz tell me how to do it
You'll have to use <pre> tags in your response so I can see your formatting. Just modify your response, then I'll have another look.
-
You'll have to use <pre> tags in your response so I can see your formatting. Just modify your response, then I'll have another look.
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison March 4, 1841
10 John Tyler April 4, 1841 -
1 George Washington April 30, 1789
2 John Adams March 4, 1797
3 Thomas Jefferson March 4, 1801
4 James Madison March 4, 1809
5 James Monroe March 4, 1817
6 John Quincy Adams March 4, 1825
7 Andrew Jackson March 4, 1829
8 Martin Van Buren March 4, 1837
9 William H. Harrison March 4, 1841
10 John Tyler April 4, 1841Are you saying you want to adjust all the lines to account for the longest?
-
Are you saying you want to adjust all the lines to account for the longest?
yes exactly
-
yes exactly
Ah, then scan through the data keeping track of the longest value length, then go through printing using those values.