Print Preview ActiveX Active Users: 83 / Visits Today: 352
Highest Active Users: 83
Print Preview ActiveX
Home | Profile | Register | Active Topics | Members | Search | FAQ | RSS
 All Forums
 Print Preview
 Tips & Tricks
 VB Routine: getNumLines

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert Email Insert CodeInsert QuoteInsert List

* Forum Code is ON
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert a File

Check here to subscribe to this topic.

T O P I C    R E V I E W
wbgookin Posted - 11/20/2004 : 02:43:42
Here's a routine I use to figure the number of lines it will take to print plain text, given a width. It works for me, but your mileage may vary.

Function getNumLines(prn As PrintPreview5.Preview, ByVal printText As String, ByVal fitWidth As Variant) As Integer
    'This routine will determine how many lines a plain text string will take to print given a width
    'prn is the previously defined preview control
    'printText is the text string to be printed
    'fitWidth is the width that you want to print the text in
    'getNumLines returns the number of lines (integer)
    'Dimension a few variables.
    'i is a counter
    'splitText() is an array that will be filled with each word (space delimited)
    'tmpText is a junk variable
    Dim i As Integer
    Dim splitText() As String
    Dim tmpText As String

    'See how many lines it is, given the width
    'Begin with one line
    getNumLines = 1
    'Split the text into the splitText array (space delimited)
    splitText = Split(printText, " ")
    'Initialize our temp string
    tmpText = ""
    'Loop through the array of words, adding one at a time to the tmpText variable
    'Each loop, check the text width.  If it is still less than the fitWidth, then keep adding words.
    'If the text width is greater than the fit width, remove the last word added, add a line to getNumLines,
    'and clear the tmpText variable.  Keep going until all the words have been added.
    For i = LBound(splitText) To UBound(splitText)
        tmpText = Trim(tmpText & " " & splitText(i))
        If prn.TextWidth(tmpText) > prn.C_Twips(fitWidth) Then
            getNumLines = getNumLines + 1
            tmpText = splitText(i)
        End If
    Next i

    'Now, in case the string is only one word, make sure it only returns one line
    If Trim(splitText(0)) = Trim(printText) Then
        getNumLines = 1
    End If

End Function

Print Preview ActiveX © Mandix Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000 Version 3.4.02