PDA

View Full Version : VB6 Help...multiline textboxes, strings and Printer.Print


Zero Tolerance
05-27-2004, 09:14 AM
All,

I've not coded alot of VB apps...and the ones that I have done have never needed the function that I am having problems with.

Anyway...I have coded a form that takes a users input with various textboxes and option buttons and prints them to the local printer.

I have everything working properly except one text box's output to the printed page. This textbox is a multiline textbox that the user can use to input "notes" about the rest of the selections on the form. Basically a multiline textbox that is being used as a "notepad". The notes can be one sentance or 20 paragraphs.

My problem is that if the user doesn MANUALLY return to a new line b4 the end of the boxview...in essence letting wordwrap take control of the return, it (the printer) will only print to the edge of the printed page and drops everything else.

Like I stated, if the user MANUALLY returns b4 the end of that line in the text box...the printer will print everything and not loose anything....however the textbox is smaller than the width dimensions of the page....so there is alot of wasted space on the page.

My question is...when you manually return does that create a seperate string or is it still considered one string? I guess I need someone to tell me or give me some code to format the printer output. Perhaps reading of the string for "x" amount of characters and words, then autoreturn so nothing is dropped.

Thanks!

Bond
05-27-2004, 09:43 AM
I'm not exactly sure if I understand what you're saying. I will try to duplicate it in a little while. But, pressing Enter in a multiline textbox is the same as adding vbCrLf to the end of the text string.

Maybe, just before you send it to the printer, you can just check to see if the text ends in a vbCrLf and, if not, add one.


If Right$(Text1.Text, 1) <> vbCrLf Then Text1.Text = Text1.Text & vbCrLf

Anaconda
05-27-2004, 11:47 AM
you need to split the line up, try using the mid function to break the string into chunks that are as long as the printer can handle, print each of these chunks followed by the CRLF sequence. Note that this will break a word mid-text, so you may want to add some additional logic to scan backwards to the nearest space, and break the line there, or to look for an appropriate hyphenation point.

in pseudo code it looks like this: (I don't remeber much VB anymore)

start = 0;
end = string length of text;
while start < end do
stop = start + printer width
if stop > end then
stop = end
printline = substring(text, start, stop);
print printline + CRLF
start = start + stop +1
loop

Zero Tolerance
05-27-2004, 01:39 PM
Bond...I'll clarify....

It is just a multiline textbox that I put in the lower corner of the program. The user can write notes in that box. If the user does NOT hit return before the end of the line...thus letting "wordwrap" do an auto return to the next line in the textbox....when printing it will drop everything in the string past the margins of the printer.

I had assumed that it treats it as one large string but wasnt sure how to get it to print from margin to margin......This way the user doesnt have to watch the textbox while typing and can also gain full capacity of the width of the paper for printing.

If the user hits return at the end or near the end of the textbox line itself it will print fine.

Hope that clears it up a bit.


Snake...ok i can see that logic....

so even though the textbox is multiline...and no matter how many times the user manually returns....it is still considered one large string?

if so....then I think I can get it fixed with said advice

Anaconda
05-27-2004, 05:55 PM
yep the text box should return everything as a single long string IIRC. If the textbox returns an array of line strings instead, then you will need to perform the above for each line returned from the text box.

Zero Tolerance
05-28-2004, 08:11 AM
ok.....ill work on it later today or monday....if it is indeed an array of strings I can just have the loop test for x' amount of blank space and kick out.

Maybe an even simpler way is to just incorporate a notepad file into this and have everything entered into the box transfered to a notepad doc and then printed from there....

I'll give it some more thought and reply later

Zero Tolerance
06-03-2004, 10:52 AM
Sorry to not post back on this sooner.....but I did get the printer to print the way that I wanted it to....however I ended up scrapping the printer.print and went with sending the contents of the form to Word so it could be saved as a file and edited at a later date...if need be.

Thanks for the suggestions guys!