|
-
Apr 11th, 2005, 02:20 PM
#1
Thread Starter
Addicted Member
<resolved> Printing a multiline textbox
Hello guys
I am printing a multiline textbox (let's say 3 lines of text) with the following code:
'------------
printer.currentX=1000
Printer.CurrentY =1000
printer.print txtMyNotes.text
'-----------
As you might guess the first line will be printed on the (1000,1000) coordinates but the second line of text will be printer at start of the next line (Something like 0,1100) !
How can I make sure the other lines of multiline text are alligned same as the first line in one bulk?
Thanks
SW
PS. The data in the multiline textbox is coming frm an Access 2000 database.
Last edited by SaharaWizard; Apr 13th, 2005 at 11:57 AM.
Don't let your schooling get in the way of your education.
-
Apr 11th, 2005, 02:56 PM
#2
Hyperactive Member
Re: Printing a multiline textbox
can u print one line at a time? then you could set the x value to 1000 before printing each line
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Apr 11th, 2005, 03:02 PM
#3
Thread Starter
Addicted Member
How?
Don't let your schooling get in the way of your education.
-
Apr 11th, 2005, 03:31 PM
#4
Re: Printing a multiline textbox
I'm not entirely sure that the CurrentY will increment properly automatically, but this should be it:
VB Code:
Dim tmpSplit as Variant
Dim iCount as Integer
tmpSplit = Split(txtMyNotes.text, vbCrLf)
Printer.CurrentY =1000
For iCount = 0 to Ubound(tmpSplit)
printer.currentX=1000
printer.print tmpSplit(iCount)
Next iCount
Moved to appropriate forum - this is not a DB question!
-
Apr 11th, 2005, 03:37 PM
#5
Re: Printing a multiline textbox
First, the CRLF in the multi-line textbox is not always present - autowrapping causes it to look like a 3 line textbox, but it can actually be one line.
This function will put "real" CRLF's into the textbox string.
Code:
strText = Wrap_Text(flxPosting.TextMatrix(x, CLng(gstrCurMP)), 3.9167 * 1440)
Printer.Print strText
This is the actual function:
Code:
Private Function Wrap_Text(ByVal strText As String, lngWidth As Long) As String
Dim x As Long, y As Long, z As Long, s1 As String
s1 = ""
Do While strText <> ""
For x = 1 To Len(strText)
Select Case Asc(Mid$(strText, x, 1))
Case 32
y = x
Case 13
Debug.Print "Got 13"
Case 10
Debug.Print "Got 10"
z = x
End Select
If z <> 0 Then
Debug.Print Left(strText, z - 2)
If s1 <> "" Then s1 = s1 & vbCrLf
s1 = s1 & Left(strText, z - 2)
strText = Mid(strText, z + 1)
z = 0
Exit For
End If
If frmTeaMark.TextWidth(Left(strText, x)) > lngWidth Then
Debug.Print Left(strText, y - 1)
If s1 <> "" Then s1 = s1 & vbCrLf
s1 = s1 & Left(strText, y - 1)
strText = Mid(strText, y + 1)
Exit For
End If
If x = Len(strText) Then
Debug.Print strText
If s1 <> "" Then s1 = s1 & vbCrLf
s1 = s1 & strText
strText = ""
Exit For
End If
Next x
Loop
Wrap_Text = s1
End Function
But in your case - you need to use SPLIT to break up the string returned by the WRAP_TEXT function on the vbCrLF - into an array - and then print each line of the array and set the .CURRENTX to 1000 first.
-
Apr 11th, 2005, 04:00 PM
#6
Re: Printing a multiline textbox
Good point, I hadn't thought that the scrollbar(s) might be disabled!
Just one point, your usage example is a little confusing! Am I right in thinking that in this case it could be added to my example like this?
VB Code:
Dim iCount as Integer
Dim strText as String
strText = Wrap_Text(txtMyNotes.text, txtMyNotes.Width)
tmpSplit = Split(strText, vbCrLf)
oh, and in the (rather useful!) function, frmTeaMark should be replaced with the name of your form.
-
Apr 11th, 2005, 04:05 PM
#7
Re: Printing a multiline textbox
Thanks SI - I'm in a rush here - it's a push-push world and I can barely keep up...
Yes - your code clarifies the usage for this thread starter...
And in the function itself "frmTeaMark" should be replaced with a form or whatever object has a good fontname, size and style to match what you are dealing with.
[edit] The function might not be commented well - but I do use DEBUG.PRINT all over!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|