rockinron
April 29th, 2001, 11:41 AM
I need code to wrap data from a database field into a text file. I can do short fields just fine but the long ones need wrapped.
the code i have will appear to wrap ok when viewing with Wordpad, Notepad or on Email attachments but when printed it is broken up into funny sections.
I heard that the API can do this.
ANY info on where i can get info on printing would be a big help also. printing seems to be tricky with VB6.
can someone help me?
Ron
shree
April 29th, 2001, 12:31 PM
Look at the following code. If you are wrapping the text to a file, then the following method is OK. It wraps on the basis of character count.
If you are wrapping to a graphical device such as a picturebox, then you need to use the GetTextExtentPoint32() API. The method is similar except that you use the condition GetTexctExtentPoint32(...)<picturebox.scalewidth in the do while loop. In addition, you may want to use the SetTextJustification() API to justify it.
private Sub Command1_Click()
dim str1 as string, str2 as string, str3 as string
dim curpos as integer
str1 = "I need code to wrap data from a database field into a text file. I can do short fields just fine but the long ones need wrapped. the code i have will appear to wrap ok when viewing with Wordpad, Notepad or on Email attachments but when printed it is broken up into funny sections. I heard that the API can do this. ANY info on where i can get info on printing would be a big help also. printing seems to be tricky with VB6. can someone help me?"
MsgBox str1
Do While len(str1) > 80
curpos = 1
str2 = mid$(str1, curpos, 80)
curpos = InStrRev(str2, " ")
str2 = Left$(str2, curpos)
str1 = mid$(str1, curpos)
str3 = str3 & LTrim(str2) & vbCrLf
Loop
MsgBox str3
End Sub
For printing, if it is plain text, then you can use
Printer.Print text1.text
If it's the contents of the picturebox that you want to print, then use
Printer.PaintPicture picture1.image, 0, 0
You may also want to let the user choose the printer to print to using the Printer Common Dialog Box.
rockinron
April 30th, 2001, 12:33 AM
i was not able to get your code to work.
i did find code to do this for me. it takes the lines one by one from a text box and i can put them into another text box, disk file, or to the printer.
thanks anyway
Ron