Not a Member Yet,
Click here to Register

ID: 420
Viewed: 3510
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Task: Description: The EASIEST way to print fully justified text!!! Place all the declarations and functions and subs 'into a .bas file:

Highlight all by clicking in box
<!---Declaration--->
'DECLARATIONS


Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Public Declare Function SetTextJustification Lib "gdi32" (ByVal hDC As Long, ByVal extra As Integer, ByVal break As Integer) As Integer
Const EM_GETLINE = &HC4
Const EM_GETLINECOUNT = &HBA

Highlight All
<!---Code--->
Function ReadLine(ByVal iLine As Long) As String

'You can change the names below if you want
With MDIForm1.ActiveForm.TextBox
Dim intRet As Long, strLineString As String

'Preparing a buffer for the string
strLineString = Space$(80)

'Reading the line
intRet = SendMessage(.hwnd, EM_GETLINE, iLine, strLineString)

'The function returns with the text of the specified line
ReadLine = strLineString
End With
End Function

Function CountStrings(ByVal where As String, ByVal what As String) As Long
Dim pos As Long, count As Long
pos = 1

'If the searched string is found
Do While InStr(pos, where, what)
pos = InStr(pos, where, what) + 1
count = count + 1
Loop

'The fucntion returns the number of occurrence of the searched string
'within the specified text
CountStrings = count
End Function

Sub FilePrintText()
Dim lLineCount As Long, lCurrLine As Long
Dim Space As Integer, extra As Integer, strPrint As String
With MDIForm1.ActiveForm.TextBox

'Determining the number of lines in the RichTextBox
lLineCount = SendMessage(.hwnd, EM_GETLINECOUNT, 0&, 0&)
End With
With Printer


'Changing the Scale Mode
.ScaleMode = vbCentimeters

'Determinig the top margin
.CurrentY = 0.5

'Determinig the PageWidth
.Width = 21

'Determinig the PageHeight
.Height = 29.7

'For all lines in the RichTextBox
For lCurrLine = 0 To lLineCount - 1

'Reading the current line
strPrint = RTrim(ReadLine(lCurrLine))

'Removing the previous values
SetTextJustification .hDC, 0, 0

'Determinig the Left margin
.CurrentX = 0.5

'Determinig the Bottom margin
If .CurrentY + .TextHeight > 28.7 Then
.NewPage
.CurrentY = 0.5
End If

'counting the spaces within the current line
Space = CountStrings(strPrint, " ")

'Determining the extra space you need to add
'to justify the current line
extra = .ScaleX(20, vbCentimeters, vbTwips) - .TextWidth(strPrint)

'Justifing the current line
SetTextJustification .hDC, extra, Space

'Sending the current line to the printer
Printer.Print strPrint
Next lCurrLine

'Printing the text
.EndDoc
End With
End Sub;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!