Sign in to follow this  
Followers 0
qwert

How to write multiple RichText fields to a file?

13 posts in this topic

I have a GUI with three RichText controls.  After the user makes entries, I have a Write button to write the entered content to a file.

If I use _GUICtrlRichEdit_StreamToFile for each individual RichText control, I get the proper RTF-formatted content, as designed.

But I can't find a method for writing all three to a single RTF file in a sequence of "append to file" operations.

I've tried constructing a separate RichText control and using _GUICtrlRichEdit_GetText and then _GUICtrlRichEdit_AppendText, but to no avail.  The result is plain text.  All formatting is removed.

What I need is the equivalent of:

FileOpen (w/Append)

FileWrite ( ... RTF1)

FileWrite ( ... RTF2)

FileWrite ( ... RTF3)

FileClose

Do I have to write 3 files and then reread/rewrite per the above steps?  I hope I'm just missing something here.

Thanks in advance for any help.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Create a small script to reproduce the issue, and someone will gladly correct it for you...or try something like this (won't run, just an example of one way):

$string = _GUICtrlRichEdit_GetText 
$string &= @CRLF & _GUICtrlRichEdit_GetText 
$string &= @CRLF & _GUICtrlRichEdit_GetText 
FileWrite(,$string)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Very intresting,

I'll try to help you..... work in progress...


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $hRichEdit, $hRichEdit2, $hRichEdit3, $hRichEdit123
    Local $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 1300, 350, -1, -1)

    #Region Create all RichEdit controls
    $hRichEdit1 = _GUICtrlRichEdit_Create($hGui, "This is a first test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit1, @CRLF & "This is more text" & @CRLF)

    $hRichEdit2 = _GUICtrlRichEdit_Create($hGui, "This is a second test.", 320, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit2, @CRLF & "This is more text" & @CRLF)

    $hRichEdit3 = _GUICtrlRichEdit_Create($hGui, "This is a third test.", 630, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit3, @CRLF & "This is more text" & @CRLF)

    $hRichEdit123 = _GUICtrlRichEdit_Create($hGui, "This is a combined test.", 940, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit123, @CRLF & @CRLF)
    #EndRegion Create all RichEdit controls

    ; Copying $hRichEdit1 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123)

    ; Copying $hRichEdit2 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123)

    ; Copying $hRichEdit3 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123)

    GUISetState(@SW_SHOW)

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit1) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit2) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit3) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit123) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

Func _GUICtrlRichEdit_CopyAllToRichEdit(ByRef $hSourceRichEdit, ByRef $hDestinationRichEdit)

    ; check for current selection in source control
    Local $aSelection = _GUICtrlRichEdit_GetSel($hSourceRichEdit)

    ; select all contents in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, 0, -1)

    ; copy selected contents from source control
    _GUICtrlRichEdit_Copy($hSourceRichEdit)

    ; paste content to destination control
    _GUICtrlRichEdit_Paste($hDestinationRichEdit)

    ; revert back selection in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, $aSelection[0], $aSelection[1])

EndFunc   ;==>_GUICtrlRichEdit_CopyAllToRichEdit

It's likely that you'll see this example in HelpFile in the next beta version of AutoIt #2769

 

EDIT:

; select selected contents in source control

changed to:

; copy selected contents from source control
Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

@mLipok, that's a good demonstration.  Here, I've expanded on it in order to give a clear confirmation of its handling of RichText formatting.

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()                                   ; modified to confirm richtext handling and to show final result

Func Example()
    Local $hGui, $hRichEdit, $hRichEdit2, $hRichEdit3, $hRichEdit123
    Local $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 1300, 350, -1, -1)

    #Region Create all RichEdit controls
    $hRichEdit1 = _GUICtrlRichEdit_Create($hGui, "This is a first test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit1, @CRLF & "This is more text" & @CRLF)
_GUICtrlRichEdit_SetSel($hRichEdit1, 0, 22)
_GUICtrlRichEdit_SetFont($hRichEdit1, 14, "Arial")
_GUICtrlRichEdit_SetSel($hRichEdit1, -1, -1)

    $hRichEdit2 = _GUICtrlRichEdit_Create($hGui, "This is a second test.", 320, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit2, @CRLF & "This is more text" & @CRLF)
_GUICtrlRichEdit_SetSel($hRichEdit2, 10, 22)
_GUICtrlRichEdit_SetFont($hRichEdit2, 14, "Arial")
_GUICtrlRichEdit_SetSel($hRichEdit2, -1, -1)

    $hRichEdit3 = _GUICtrlRichEdit_Create($hGui, "This is a third test.", 630, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit3, @CRLF & "This is more text" & @CRLF)
_GUICtrlRichEdit_SetSel($hRichEdit3, 10, 21)
_GUICtrlRichEdit_SetFont($hRichEdit3, 14, "Arial")
_GUICtrlRichEdit_SetSel($hRichEdit3, -1, -1)

    $hRichEdit123 = _GUICtrlRichEdit_Create($hGui, "This is a combined test.", 940, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit123, @CRLF & @CRLF)
    #EndRegion Create all RichEdit controls
    GUISetState(@SW_SHOW)

MsgBox(0, "", "Pause", 1)
    ; Copying $hRichEdit1 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123)
MsgBox(0, "", "Pause", 1)
    ; Copying $hRichEdit2 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123)
MsgBox(0, "", "Pause", 1)
    ; Copying $hRichEdit3 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123)
Local $Var = _GUICtrlRichEdit_StreamToVar($hRichEdit123, True)
MsgBox(0, "Result", $Var, 0)
_GUICtrlRichEdit_StreamToFile($hRichEdit123, @ScriptDir & "\Rich123.rtf", True)

    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit1) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit2) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit3) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit123) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

Func _GUICtrlRichEdit_CopyAllToRichEdit(ByRef $hSourceRichEdit, ByRef $hDestinationRichEdit)

    ; check for current selection in source control
    Local $aSelection = _GUICtrlRichEdit_GetSel($hSourceRichEdit)

    ; select all contents in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, 0, -1)

    ; copy selected contents from source control
    _GUICtrlRichEdit_Copy($hSourceRichEdit)

    ; paste content to destination control
    _GUICtrlRichEdit_Paste($hDestinationRichEdit)

    ; revert back selection in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, $aSelection[0], $aSelection[1])

EndFunc   ;==>_GUICtrlRichEdit_CopyAllToRichEdit

I had actually explored using the clipboard, based on a 5-year-old forum entry I found.  But I had set it aside because of its potential impact on a user's other applications and actions.

At this moment, I'm working on another approach, which I'll build into an example and post soon.

Thanks for taking the time to look at this.  I imagine many will benefit from what you've demonstrated.  And it may well turn out to be the most practical method.

 

Share this post


Link to post
Share on other sites

As I explained in my original post, my goal is to write 3 RichEdit controls to a single RTF file.

 

As shown by the following 2-control example, it appeared that I could put the contents of the controls into an array and then write out the array.

 

But it doesn’t work. Only the first array entry is written.

 

;
;       SIMPLE TEST OF 2 RTF FIELDS:
;       Attempt to write Rich Text controls to a single file
;
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Local $hGui, $hRichEdit, $iMsg
Local $Var[2]
;                           QUESTION 1:  how to have SetFont apply to RichEdit controls?
$hGui = GUICreate("Example ", 320, 340, -1, -1)
GUISetFont(14, 400, 0, "Arial")
$hRich1 = _GUICtrlRichEdit_Create($hGui, "This is the first field.", 10, 20, 300, 120, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$hRich2 = _GUICtrlRichEdit_Create($hGui, "This is the second.", 10, 160, 300, 120, $ES_MULTILINE) ;, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$Button = GUICtrlCreateButton("Write", 120, 300, 100, 26)
GUISetState()

While True
    $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
             _GUICtrlRichEdit_Destroy($hRich1)
             _GUICtrlRichEdit_Destroy($hRich2)
             Exit
        Case $iMsg = $Button
        $Var[0] = _GUICtrlRichEdit_StreamToVar($hRich1, True)
        $Var[1] = _GUICtrlRichEdit_StreamToVar($hRich2, True)
        MsgBox(0, "Rich1", $Var[0], 0)
        MsgBox(0, "Rich2", $Var[1], 0)
        If IsArray($Var) Then               ; QUESTION 2: why is Rich2 content not written by the WriteFromArray operation?
            FileOpen(@ScriptDir & "\Rich.rtf", 2)
            _FileWriteFromArray(@ScriptDir & "\Rich.rtf", $Var, 0, 1)
            FileClose(@ScriptDir & "\Rich.rtf")
        EndIf
    EndSelect
WEnd

At this point, my two questions are:

 

1: how to have SetFont apply to RichEdit controls?

 

2: why is Rich2 content not written by the WriteFromArray operation?

 

Thanks for any help.

 

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

first element contain something like this RTF START RTF STOP

second element contain something like this RTF START RTF STOP

what you think when you write this to one file, what is his content ?

RTF START RTF STOP + RTF START RTF STOP

What do a Viewer (wordpad) ? display content from first RTF START to first RTF STOP, and omnits the second part.

It was very simple explanation, but I think very accurate.

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

That's a good point.  So the select/copy/paste sequence fiddles with the RTF "bracketing", but the sequential writing of independent fields doesn't.

I guess some post-processing of the array will be necessary if I'm going to avoid using the clipboard.

It looks like I have some homework to do.

Share this post


Link to post
Share on other sites

exactly.

Cheers

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

did you try $SFF_SELECTION ?

I chceck it inside:
 

_GUICtrlRichEdit_StreamToVar()
_GUICtrlRichEdit_StreamFromVar()

but I think I found bug #2781 in related function:

_GUICtrlRichEdit_IsTextSelected()

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

mLipok,

 

but I think I found bug [...] in related function

Think again - #2781. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Well

Last days I have trouble with analysis (I'm sick - flu)

Thanks for the kick.


Here is my full solution to this thread (without using clipboard)

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGui, $hRichEdit, $hRichEdit2, $hRichEdit3, $hRichEdit123
    Local $iMsg
    $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 1300, 350, -1, -1)

    #Region Create all RichEdit controls
    $hRichEdit1 = _GUICtrlRichEdit_Create($hGui, "This is a first test.", 10, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit1, @CRLF & "This is more text" & @CRLF)

    $hRichEdit2 = _GUICtrlRichEdit_Create($hGui, "This is a second test.", 320, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit2, @CRLF & "This is more text" & @CRLF)

    $hRichEdit3 = _GUICtrlRichEdit_Create($hGui, "This is a third test.", 630, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit3, @CRLF & "This is more text" & @CRLF)

    $hRichEdit123 = _GUICtrlRichEdit_Create($hGui, "This is a combined test.", 940, 10, 300, 220, _
            BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    _GUICtrlRichEdit_AppendText($hRichEdit123, @CRLF & @CRLF)
    #EndRegion Create all RichEdit controls

    GUISetState(@SW_SHOW)

    ; Copying $hRichEdit1 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123)

    ; Copying $hRichEdit2 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123)

    ; Copying $hRichEdit3 to $hRichEdit123
    _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123)


    While True
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                _GUICtrlRichEdit_Destroy($hRichEdit1) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit2) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit3) ; needed unless script crashes
                _GUICtrlRichEdit_Destroy($hRichEdit123) ; needed unless script crashes
                ; GUIDelete()   ; is OK too
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

Func _GUICtrlRichEdit_CopyAllToRichEdit(ByRef $hSourceRichEdit, ByRef $hDestinationRichEdit)

    Local $vRichEdit_Stream =''
    ; check for current selection in source control
    Local $aSelection = _GUICtrlRichEdit_GetSel($hSourceRichEdit)

    ; select all contents in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, 0, -1)

    ; select selected contents in source control
    $vRichEdit_Stream = _GUICtrlRichEdit_StreamToVar($hSourceRichEdit)

    ; add one char
    _GUICtrlRichEdit_AppendText($hDestinationRichEdit, ' ')

    ; select last char
;~  _GUICtrlRichEdit_SetSel($hDestinationRichEdit, _GUICtrlRichEdit_GetTextLength($hDestinationRichEdit)-1, -1)
    _GUICtrlRichEdit_SetSel($hDestinationRichEdit, StringLen(_GUICtrlRichEdit_GetText($hDestinationRichEdit))-1, -1)

    ; paste content to destination control
    _GUICtrlRichEdit_StreamFromVar($hDestinationRichEdit, $vRichEdit_Stream)

    ; revert back selection in source control
    _GUICtrlRichEdit_SetSel($hSourceRichEdit, $aSelection[0], $aSelection[1])

EndFunc   ;==>_GUICtrlRichEdit_CopyAllToRichEdit


QUESTION: 

why there is a different between this two followed line:

_GUICtrlRichEdit_SetSel($hDestinationRichEdit, _GUICtrlRichEdit_GetTextLength($hDestinationRichEdit)-1, -1)
_GUICtrlRichEdit_SetSel($hDestinationRichEdit, StringLen(_GUICtrlRichEdit_GetText($hDestinationRichEdit))-1, -1)

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Thanks for the alternate method you've provided.  Appending and then replacing a single character circumvents a lot of potential pitfalls in other methods which attempt to micromanage the RTF format commands.  As a safeguard against eventual "interruptions" in the process of appending, I'm going to use a character like # as a visible indicator.  IOW, if I ever find # at the end of a RTF block, I'll know that an attempted append failed for some reason.

In my current RTF application, I'm opening an existing RTF file and appending new content.  Your new method fills the bill, nicely, in avoiding use of the clipboard.

In answer to your question, I believe the difference is that the first count includes all the formatting command characters.  The second count is only viewable text characters.  The block below shows a typical difference in the sizes.

One clarification that I will offer to anyone reading about the RichEdit stream to/from file operations is that the UDF functions handle the needed file open/close operations.  It took me some time to figure out why I was getting strange error returns and/or 0 bytes written.  A clarification needs to be added to the help file.

 

 

post-29172-0-29797000-1404348571.png

Share this post


Link to post
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
Sign in to follow this  
Followers 0