vbCrLf problem or other bugs for printing?

flexpress
09-05-2003, 02:11 AM
Visual Basic 6

Please help!!!!! I asked the same question on vbforums.com but no anwser yet, I hope I can get response here, many thanks.

I'm a VB6 Novice and I'm trying to get a text box that's had text flowed into it, to print every line.

My normal procedure would be to look for the vbCrLf, but there's not one!

Does anyone know of a simple but of code that will enable me to print all lines of the text box.

-----------------------
Example:

If I type the long text " flat 8, room5, michael lewis house, 3 sed street, London, United Kingdom , LO3, E79" on address box, the text flows automatically depends on the box size, but when I print the page, it just shows one line, and the last 2 words come out to my A4 paper.
-----------------------

Any help gratefully appreciated!

navet1ss
09-05-2003, 05:11 AM
I'm assuming you have a textbox with multiline=true and scrollbars=none. In this case what you are seeing is correct. Remember that all you are doing with the properties is telling the textbox how to display the text, not how to format it. In order to get properly formatted text from a textbox you have to get the user to type it in that way or write code to format it. In this case it's probably easier to set the scrollbars=horizontal and have the user type the text the way you want to see it (including vbCrLf).

Chris J Locke
09-05-2003, 05:23 AM
As you're using VB6, you could use the SPLIT command and split the long line into an array using the comma as a delimiter. It wouldn't be 100% foolproof, but it would be better than one long line...

Thinker
09-05-2003, 08:17 AM
Since there are no hard line breaks, you have to break the lines based
on the available printing space. If you have the textbox sized where the
lines break at exactly the same place they need to in printing, then it is
a matter of using an API function, SendMessage, to send the
EM_FMTLINES message to the textbox, then use the Replace() function
to change all occurrences of the string vbCr & vbCrLf to just vbCrLf.
Don't forget to send another message to change the format back.

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Private Const EM_FMTLINES As Long = &HC8

Private Function GetTextLines(myTextbox As Textbox) As String
Dim tmpStr As String

SendMessage myTextbox.hWnd, EM_FMTLINES, True, ByVal 0
tmpStr = myTextbox.Text
GetTextLines = Replace(tmpStr, vbCr & vbCrLf, vbCrLf)
SendMessage myTextbox.hWnd, EM_FMTLINES, False, ByVal 0
End Function

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum