Jump to content

printing text with without CR/LF


Recommended Posts

Hi there,

I'm using the print udf and i wonder if it is possible to print a long line of text using line wrapping (that is the correct word I think)

e.g. í'm having a $text wich contains 500 characters or more including points, commas and so on, but no carrige return or linefeed characters.

What can I Use to print this line of text on a A4 printer and be sure the text is broken by the space and not in the middel of a word.

perhaps it's been asked before, but I cann't find it in the topics.

Link to comment
Share on other sites

  • Moderators

albertmaathuis,

You might like to look at my StringSize UDF (the link is in my sig) which as well as returning the size of the text also returns the text itself with the wrapping @CRLF inserts. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

This may help

;$sSplitIndex : the Number from where the Space Split would be Started

Func _CRFromSpace($sString,$sSplitIndex=-1)
    If $sSplitIndex=-1 Then Return StringReplace($sString,' ',@CR)
    Local $nString=StringSplit($sString,' ',1)
    If @error Then Return SetError(1,@error,-1)
    Local $nLen=0
    For $i=1 To $nString[0]
        $nLen+=StringLen($nString[$i])+1
        If $nLen>$sSplitIndex Then
            Return StringReplace($sString,$nLen,@CR)
        EndIf
    Next
    $nLen-=1
    Return SetError(2,$nLen,-1)
EndFunc

Local $aRet=_CRFromSpace('Hello There My Name is Anthony Gonsalvis',17)
ConsoleWrite($aRet&@CR)
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • Moderators

albertmaathuis,

I have just tested and it downloads fine for me. Perhaps try copy and paste from the forum post. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

I'm going to use the solution from PhoenixXL. Working on a 64 bit server might give me problems with the dll's used in M23 program.

I made a slight difference in the code, because i want it to brake the string before the last word. In that case I'm sure that my printer doesn't print outside its margins.

Thanks for the help; below is the code i'm going to use.

Global $previousspace,$newtext,$maxwidth

$text="Visit Vinsobres in the Drôme Provençale.The large weekly markets of Nyons and Vaison la Romaine can provide you with delicious local products. For the wine lovers, there are excellent wines. The red Vinsobres is classified as the first vintage of the Côtes du Rhône in the Drôme Provençale. On foot, by bike or by car, you can explore the many cultural and historic sites or enjoy the sun and the peace on the edge of the swimming pool."

$len=StringLen($text)
$maxwidth=50; This is the maximum width of the new text.

Do
$aRet=_CRFromSpace($text,$maxwidth)
$newtext=$newtext&@CRLF&StringLeft($text,$previousspace)
$len=StringLen($text)
$text=StringRight($text,$len-$previousspace)
until $len<$maxwidth
msgbox(0,"output",$newtext)

Func _CRFromSpace($sString,$sSplitIndex=-1)
    If $sSplitIndex=-1 Then Return StringReplace($sString,' ',@CR)
    Local $nString=StringSplit($sString,' ',1)
    If @error Then Return SetError(1,@error,-1)
    Local $nLen=0
    For $i=1 To $nString[0]; het aantal brokken van de string
        $nLen+=StringLen($nString[$i])+1; nlen is de teller van de spaties, de 1e spatie staat op 4, daarna op 9
        If $nLen>$sSplitIndex Then; splitindex is dat getal waarNA de string wordt afgebroken.
   Return StringReplace($sString,$previousspace,@CR); de string wordt nu nooit langer dan de opgegeven waarde
  Else
   $previousspace=$nLen
        EndIf
    Next
    $nLen-=1
    Return SetError(2,$nLen,-1)
EndFunc
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

albertmaathuis,

Working on a 64 bit server might give me problems with the dll's used in M23 program

No-one has ever reported any problem with the UDF when used with an x64 OS - please let me know if you do. :)

And when you post code in future, please use Code tags - put [autoit] before and [/autoit] after your posted code. I have done it for you above. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...