I wrote these code to print the description in the text box and the output is like it can't print the text as what it shown in the text box or text file (The descriptions were stored in a text file). Certain lines in a paragraph were skipped until a suppose to be long document (description) printed as short/uncompleted. Seems like the printer can't "wrap" the paragraph to make the text fit to the page.
My initial reaction would be that you would want to SPLIT the string in the text box using vbCr or VbCrLf - not sure what you have for a line-break in the text...
Once you SPLIT the string into the ARRAY, then print one line at a time.
Hi szlamany,
I have a list box where the user select an item from the list box, and the description of the item will be display in a text box. Different item will display different description in the same text box. Refer http://www.vbforums.com/showthread.p...xtbox+Resolved
These are the code I use to separate the description:
You have a string that is too big for the printer to print on one line.
So you need to cut it up.
I ripped this from a program we have here - I had to make edits in NOTEPAD to remove a whole lot of other stuff it was doing - hopefully it will work for you as is. x, y and z are dim'd long and strPara is the string to print.
VB Code:
Do While Len(strPara)
y = Printer.Width ' Width in twips of printer
If Printer.TextWidth(strPara) > y Then ' Size of what we want to print is too big
z = Len(strPara) ' Length of it in characters
Do While Printer.TextWidth(Left(strPara, z)) > y
z = z - 1 ' Backup until it will fit
Loop
y = z ' Position that fits
z = Asc(Mid(strPara, y + 1, 1)) ' ASC value of next character
If z <> 32 Then ' That next character is not a space
z = Asc(Mid(strPara, y, 1))
Do While z <> 32 ' Start backing up till we find the space
Yup, the printer now can wrap the text to next line for printing, but the printing is too near to the edge of paper and there's some words that near to the edge missing. I used an A4 paper for printing.
BTW, after I clicked “Print”, the printer takes about 1 minute to process before it started to print, is this normal?
If you are going to use TEXTWIDTH - which is a twip-level length function, then you should not use TAB().
Instead set .CURRENTX to a twip value that represents the position form the left side that you want to indent.
This position that you use - this value - would most likely also be the number to subtract from the PRINTER.WIDTH - since that is the "offset" from the left-side that you are using.
The one-minute thing makes no sense - try adding a PRINTER.NEWPAGE before the .ENDDOC to see if it prints/ejects the page immediately - just for a test. Don't leave the .NEWPAGE in there, unless you really want to print a second page.
I added Printer.CurrentX = 720 before Printer.Font.Size = 10 and it only indent the first line of the description. If I put Printer.CurrentX = 720 before y = Printer.Width - 720, then the left indention goes some kind like randomly. Since what I use in the left-side will be "offset" from the PRINTER.WIDTH, it's pretty hard to balance both side's indention.
I added .NEWPAGE before the .ENDDOC, but it still takes about 1 minute to process, this is weird.
CurrentX must be prior to printing each line. The PRINTER.PRINT method, without a ";" trailing the string, will increment the CURRENTY to the next print line and set CURRENTX to zero.
Since you are setting CURRENTX before printing EACH line, do not use TAB() - do a direct PRINTER.PRINT xxx where xxx represents the line (string) you want to print.
I'm still having problem with the left indention and it takes a long time for the printer to process before it print. I guess maybe the String is too big, because I had tried to print a description with less text and the printer print immediately; but when I tried to print a description with lots of text, it takes about 1~2 minutes to process before the printer start to print.