PRINT listview in tabular and formatted text
PRINT listview in tabular and formatted text
(OP)
i have a listview with data in image.
i need to send the value to the printer in a tabular mode...
the param are:
max lenght for each row 60 character max
for
REPARTO max lenght 34 align to the left
ID max lenght 3 align to the center
qty max lenght 3 align to the center
PREZZO max lenght 10 align to the right
TOT. max lenght 10 align to the right
max lenght of each row 34+3+3+10+10
possible?
i need to send the value to the printer in a tabular mode...
the param are:
max lenght for each row 60 character max
for
REPARTO max lenght 34 align to the left
ID max lenght 3 align to the center
qty max lenght 3 align to the center
PREZZO max lenght 10 align to the right
TOT. max lenght 10 align to the right
max lenght of each row 34+3+3+10+10
possible?
RE: PRINT listview in tabular and formatted text
For Each listy In ListView1.ListItems
Debug.Print listy; Tab(34);
Debug.Print Spc((3 - Len(listy.ListSubItems(1))) / 2); listy.ListSubItems(1); Tab(38);
Debug.Print Spc((3 - Len(listy.ListSubItems(2))) / 2); listy.ListSubItems(2); Tab(41);
Debug.Print Spc(10 - Len(listy.ListSubItems(3))); listy.ListSubItems(3); Tab(51);
Debug.Print Spc(10 - Len(listy.ListSubItems(4))); listy.ListSubItems(4)
Next
RE: PRINT listview in tabular and formatted text
Stringm you are a genius!
Tks.
RE: PRINT listview in tabular and formatted text
possible to print also a header title of each column of listview , to the head of row?
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
Myself, I like to use a screwdriver from time to time when screws are used, or a wrench when nuts and bolts are involved.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
sal21 said: "i love it" ('it' being Listviews) I love (well, like) to use controls I am familiar with, I know how to use them and don't have to ask for help. [hint]
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
strvar="PAGAMENTO ELETTRONICO:"
or
strvar="PAGAMENTO CONTANTI:"
or
strvar="RESTO:"
ecc...
and a var strnumber="0,25"
the max leght of string, to print, is 60.
now, based the strvar, i need to printer.print, similar:
strvar<(align to the left) strnumber<(to align to the right)
naturally strnumber have a variable lenght(11,58, 5,48, 650,45 ...ecc)
how to?
RE: PRINT listview in tabular and formatted text
CODE
To get as an outcome:
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
but i need eaxclly the opposite:
RESTO: 0,25
RE: PRINT listview in tabular and formatted text
CODE
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
CODE -->
RE: PRINT listview in tabular and formatted text
my angels!
tks
2009luca and sal21, are
it's always me.
have 2 account
RE: PRINT listview in tabular and formatted text
...
Printer.Print .ColumnHeaders(1).Text; Tab(34);
Printer.Print Spc((3 - Len(.ColumnHeaders(2).Text)) / 2); .ColumnHeaders(2).Text; Tab(38);
Printer.Print Spc((3 - Len(.ColumnHeaders(3).Text)) / 2); .ColumnHeaders(3).Text; Tab(41);
Printer.Print Spc(10 - Len(.ColumnHeaders(4).Text)); .ColumnHeaders(4).Text; Tab(51);
Printer.Print Spc(10 - Len(.ColumnHeaders(5).Text)); .ColumnHeaders(5).Text
....
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
Printer.Print Spc((3 - Len(.ColumnHeaders(2).Text)) / 2); .ColumnHeaders(2).Text; Tab(38);
similar:
STRINGA = .Print Spc((3 - Len(.ColumnHeaders(2).Text)) / 2); .ColumnHeaders(2).Text; Tab(38);
RE: PRINT listview in tabular and formatted text
We can build it via a nUmber of Format functions, eg:
STRINGA = Format(listy, "!" & String(34, "@")) & Format(listy.ListSubItems(1), "@@@") & Format(listy.ListSubItems(2), "@@@") & Format(listy.ListSubItems(3), "@@@@@@@@@@") & Format(listy.ListSubItems(4), "@@@@@@@@@@")
And here's that inserted into my example code duplicating the original method. There are also a couple of minor tweaks:
1) FRixed a positioning bug, as I used wrong tab for first parameter
2) Removed some of the 'centering' code, as with only a 3 character space in a fixed width solution it really didn't do very much useful
CODE
Dim listy As ListItem With ListView1 Debug.Print .ColumnHeaders(1); Tab(35); ' corrected from previous version Debug.Print .ColumnHeaders(2); Tab(38); Debug.Print .ColumnHeaders(3); Tab(41); Debug.Print Spc(10 - Len(.ColumnHeaders(4))); .ColumnHeaders(4); Tab(51); Debug.Print Spc(10 - Len(.ColumnHeaders(5))); .ColumnHeaders(5) ' Alternative version that actually builds a string Debug.Print Format(.ColumnHeaders(1), "!" & String(34, "@")) & Format(.ColumnHeaders(2), "!@@@") & Format(.ColumnHeaders(3), "!@@@") & Format(.ColumnHeaders(4), "@@@@@@@@@@") & Format(.ColumnHeaders(5), "@@@@@@@@@@") End With For Each listy In ListView1.ListItems Debug.Print listy; TabTab(35); ' corrected from previous version Debug.Print listy.ListSubItems(1); Tab(38); Debug.Print listy.ListSubItems(2); Tab(41); Debug.Print Spc(10 - Len(listy.ListSubItems(3))); listy.ListSubItems(3); Tab(51); Debug.Print Spc(10 - Len(listy.ListSubItems(4))); listy.ListSubItems(4) ' Alternative version that actually builds a string Debug.Print Format(listy, "!" & String(34, "@")) & Format(listy.ListSubItems(1), "!@@@") & Format(listy.ListSubItems(2), "!@@@") & Format(listy.ListSubItems(3), "@@@@@@@@@@") & Format(listy.ListSubItems(4), "@@@@@@@@@@") Next
It's be great if we could use some sort of single formatting function to feed strings, alignment and position to be built into a final string, but the VB(A) format function isn't quite that flexible ... but VB.NET has such a flexible, powerful formatting capability. If only we could use it somehow ...
RE: PRINT listview in tabular and formatted text
but have a dubt...
you fixed a position of first element to 35, and i see in Format(.ColumnHeaders(1), "!" & String(34, "@"))... 34, is correct?
the code work in other case!
RE: PRINT listview in tabular and formatted text
So, if a string is 34 characters long, the next position would be 35
Oh, and no-one biting on the "If only we could use it somehow"? It was a leading question ... (although it leads into slightly esoteric areas; for those that want a hint, have a look at my code in thread329-1570966: A Format function for VbScript)
RE: PRINT listview in tabular and formatted text
sorry me, but prob to center text
CODE
i have modifiyed the code, because instead 3 digit i need 4 digit, always for 60 lenght string.
tghe valuye not is centered... see image
thevalue are in:
REPARTO ID QTY PREZZO TOT.
------------------------------------------------------------
13-NOLEGGIO SPIAGGIA 101 2 15,00 30,00
1-CAFFETTERIA 1 4 1,00 4,00
i need to center the value in ID and QTY
note:
this code print value in a richtextbox
RE: PRINT listview in tabular and formatted text
By now you probably have noticed that everybody here shows you code formatted as code. It is a lot easier to read than just simple text, and you can differentiate between 'explanation' and 'code' in the posts.
Why don't you format your code as CODE...
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
modified
RE: PRINT listview in tabular and formatted text
Define: center
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
RE: PRINT listview in tabular and formatted text
You sure? I ask because it isn't actually possible to center if using a fixed width font and print statements; I skated over that in earlier solutions, because with a 3 char column it isn't really noticeable that we didn't really center it (we just decided to go with left aligned)
For example
Single digit can be 'centered' in two positions - which would you want?
.9..
..9.
2 and 4 digits can be centered
.99.
9999
And three digits can be 'centered' in two positions
.999
999.
RE: PRINT listview in tabular and formatted text
You have a column ID, which is 2 characters.
To 'Center' a 2 digits ID, it would be:
To 'Center' a 4 digits ID, it would be:
How do you 'center' 1 digit? Or 3 digits?
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
yes!
2 and 4 digits can be centered for ID
.99.
9999
RE: PRINT listview in tabular and formatted text
What I would do is:
CODE
Besides of renaming RichTextBox1 to something more meaningful, and use more standardized naming conventions, like strDBRows, strPRZ, strTotale (STOTALE), strA (STRINGA ) etc.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: PRINT listview in tabular and formatted text
I jhave see the second with dont refer to nothing, correct!
i cannot test now your code... i'm busy, wiht my wife in cucine! Pizza!!!!
RE: PRINT listview in tabular and formatted text