Jump to content
Sign in to follow this  
gfcaim

Multi line Edit

Recommended Posts

gfcaim

This is going to be really simple I know, but...

On my form I have a multi-line edit, which works fine in itself - I can write then hit return and write again and get multi-line text. This edit is actually the body of an email in my app, but when I send the email, it arrives in my inbox with all the text on one line, not multi-line as entered.

It is created thus:

$txtMsg = GUICtrlCreateEdit("", 184, 32, 281, 153)

and ES_MULTILINE is checked (in fact, checked and greyed out)

It is accessed thus:

$eBody=ControlGetText("","",8)

but equally I have tried:

$eBody=GUICtrlRead(8)

and

$eBody= StringReplace(ControlGetText("","",8), @CRLF, chr(10) & chr(13))

all to no avail.

Can someone please point me in the right direction...


[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
Melba23

gfcaim,

If the edit control is one you created, which looks to be the case, then GUICtrlRead is the command to use. However, this should include the @CRLFs. :mellow:

Could it be that your e-mail client is reformatting the text for you? Have you tried displaying a MsgBox to check the formatting once you have placed the text into a variable for sending?

Perhaps if you posted the whole script we might get a better idea. :P

M23

P.S. I note you are using raw ControlIDs ($eBody=GUICtrlRead(8)) - it is much better practice to use a variable which you set as the control is created. That way you do not have to worry about inserting any further controls into your script and having to amend all the numbers! :party:


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
gfcaim

Thanks for your time Melba:

1) Ok, changed the read method to GUICtrlRead - thanks.

2) Yes, good call - indeed a msgbox displayed correctly - this gives me a problem now for sure! (email client is Outlook 2007)

3) Regarding using raw control IDs, this was, in fact, going to be the subject of my next post for help - how to avoid having to scan my code to alter all these each time I made a code change! So thanks for spotting that, but would you have a quick example of how to set the IDs?

My code is as follows, don't laugh! - Comments very welcome - i'm only learning!

opt("MustDeclareVars",1)
Const $appName = "Quick eMailer v1.2"
Dim $frmMain,$cmdSend,$lbxAddresses,$txtAddAddr,$txtSubject,$txtMsg,$lbxAddressescontext,$cmnuAddAddr,$cmnuRemAddr
Dim $eTo,$eSubj,$eBody,$oOApp,$oOMail,$File,$Line
Dim $nMsg,$Res,$SelAddr,$i,$Cnt,$OkToSend
;-------------------------------------------------------
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;-------------------------------------------------------
#Region ### START Koda GUI section ###
$frmMain = GUICreate($appName, 473, 213, -1, -1)
$cmdSend = GUICtrlCreateButton("Send", 384, 184, 81, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Send email")
$lbxAddresses = GUICtrlCreateList("", 8, 8, 169, 173, BitOR($LBS_SORT,$LBS_MULTIPLESEL))
GUICtrlSetTip(-1, "To:")
$lbxAddressescontext = GUICtrlCreateContextMenu($lbxAddresses)
$cmnuAddAddr = GUICtrlCreateMenuItem("Add Address", $lbxAddressescontext)
$cmnuRemAddr = GUICtrlCreateMenuItem("Remove Addresses", $lbxAddressescontext)
$txtAddAddr = GUICtrlCreateInput("", 8, 184, 169, 21)
GUICtrlSetTip(-1, "Enter new email address")
$txtSubject = GUICtrlCreateInput("", 184, 8, 281, 21)
GUICtrlSetTip(-1, "Subject:")
$txtMsg = GUICtrlCreateEdit("", 184, 32, 281, 149)
GUICtrlSetData(-1, "")
GUICtrlSetTip(-1, "Body:")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;-------------------------------------------------------
ReadiniFile()
While 1
    $nMsg = GUIGetMsg()
    $OkToSend=true
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
            ;Quit
            WriteiniFile()
            Exit
        Case $cmnuAddAddr
            ;Add email address to list
            $SelAddr=ControlGetText("","",8)
            if StringLen($SelAddr) > 0  then
                if StringInStr ($SelAddr, "@")=0 or StringInStr ($SelAddr, ".")=0  then
                    msgbox(64,$appName,"This doesn't look like a valid email address...")
                else
                    _GUICtrlListBox_AddString($lbxAddresses, $SelAddr)
                    ControlSetText("","",8,"")
                endif
            endif
        Case $cmnuRemAddr
            ;Remove email address from list
            if _GUICtrlListBox_GetSelCount($lbxAddresses) >0 then
                $Cnt=msgbox(292,$appName,"Remove selected addresses?")
                if $Cnt=6 then
                    do
                        $SelAddr=_GUICtrlListBox_GetSelItems ($lbxAddresses)
                        if $SelAddr[0] > 0 Then
                            $Cnt=0
                            _GUICtrlListBox_DeleteString ($lbxAddresses,$SelAddr[1])
                        Else
                            $Cnt=1
                        EndIf
                    Until $Cnt=1
                endif
            endif
        Case $lbxAddresses
            ;No action needed
        Case $cmdSend
            ;Send email
            $SelAddr=_GUICtrlListBox_GetSelItemsText($lbxAddresses)
            if $SelAddr[0] = 0 Then
                msgbox(16,$appName,"Error - No recipient entered...")
                $OkToSend=false
            elseif $SelAddr[0] = 1 Then
                $eTo=$SelAddr[1]
            else
                $eTo=$SelAddr[1]
                for $i = 2 to $SelAddr[0]
                    $eTo=$eTo & "; " & $SelAddr[$i]
                next
            endif
            $eSubj=ControlGetText("","",9)
            $eBody=GUICtrlRead(10)
            msgbox(0,"",$eBody)
            if $OkToSend=true then SendEmail($eTo,$eSubj,$eBody)
            if $Res= true then
                ControlSetText("","",3,"Sent Ok...")
                Sleep(2000)
                ControlSetText("","",3,"Send")
            endif
    EndSwitch
WEnd
;-------------------------------------------------------
Func SendEmail($eTo,$eSubj,$eBody)
    Local $olMailItem = 0
    Local $olByValue = 1
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    ;$oOMail.Save
    With $oOMail
        .To = $eTo
        .Subject = $eSubj
        .HTMLBody = $eBody
        .BodyFormat = 2;Plain=1, HTML=2, RichText=3
        .Importance = 1;Low=0, Normal=1, High=2
        .Send
    EndWith
    $oOApp=0
    $Res = true
EndFunc
;-------------------------------------------------------
func ReadiniFile()
    $file = FileOpen("eMailer.ini", 0)
    If $file = -1 Then
        MsgBox(64, $appName, "No addresses file exists. A new one will be created.")
    Else
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            _GUICtrlListBox_AddString($lbxAddresses, $line)
        Wend
        FileClose($file)
    EndIf
EndFunc
;-------------------------------------------------------
Func WriteiniFile()
    $file = FileOpen("eMailer.ini", 2)
    $Cnt=_GUICtrlListBox_GetCount($lbxAddresses)
    if $Cnt>0 Then
        for $i = 0 to ($Cnt-1)
            $line=_GUICtrlListBox_GetText($lbxAddresses,$i)
            FileWriteLine($file, $line & @CRLF)
        next
    endif
    FileClose($file)
EndFunc

[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
Melba23

gfcaim,

don't laugh

I try never to laugh "at", only "with" - after all, we all started at the same level at some time in our lives! :P

Here is an amended script to show how you use the variables set at creation to identify the controls:

;-------------------------------------------------------
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;-------------------------------------------------------

Opt("MustDeclareVars", 1)

Const $appName = "Quick eMailer v1.2"
Dim $frmMain, $cmdSend, $lbxAddresses, $txtAddAddr, $txtSubject, $txtMsg, $lbxAddressescontext, $cmnuAddAddr, $cmnuRemAddr
Dim $eTo, $eSubj, $eBody, $oOApp, $oOMail, $File, $Line
Dim $nMsg, $Res, $SelAddr, $i, $Cnt, $OkToSend

#Region ### START Koda GUI section ###
$frmMain = GUICreate($appName, 473, 213, -1, -1)
$cmdSend = GUICtrlCreateButton("Send", 384, 184, 81, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Send email")
$lbxAddresses = GUICtrlCreateList("", 8, 8, 169, 173, BitOR($LBS_SORT, $LBS_MULTIPLESEL))
GUICtrlSetTip(-1, "To:")
$lbxAddressescontext = GUICtrlCreateContextMenu($lbxAddresses)
$cmnuAddAddr = GUICtrlCreateMenuItem("Add Address", $lbxAddressescontext)
$cmnuRemAddr = GUICtrlCreateMenuItem("Remove Addresses", $lbxAddressescontext)
$txtAddAddr = GUICtrlCreateInput("", 8, 184, 169, 21)
GUICtrlSetTip(-1, "Enter new email address")
$txtSubject = GUICtrlCreateInput("", 184, 8, 281, 21)
GUICtrlSetTip(-1, "Subject:")
$txtMsg = GUICtrlCreateEdit("", 184, 32, 281, 149)
GUICtrlSetData(-1, "")
GUICtrlSetTip(-1, "Body:")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;-------------------------------------------------------

ReadiniFile()

While 1
    $nMsg = GUIGetMsg()
    $OkToSend = True
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ;Quit
            WriteiniFile()
            Exit
        Case $cmnuAddAddr
            ;Add email address to list
            $SelAddr = GUICtrlRead($txtAddAddr) ; How to use ControlIDs <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            If StringLen($SelAddr) > 0 Then
                If StringInStr($SelAddr, "@") = 0 Or StringInStr($SelAddr, ".") = 0 Then
                    MsgBox(64, $appName, "This doesn't look like a valid email address...")
                Else
                    _GUICtrlListBox_AddString($lbxAddresses, $SelAddr)
                    ControlSetText("", "", 8, "")
                EndIf
            EndIf
        Case $cmnuRemAddr
            ;Remove email address from list
            If _GUICtrlListBox_GetSelCount($lbxAddresses) > 0 Then
                $Cnt = MsgBox(292, $appName, "Remove selected addresses?")
                If $Cnt = 6 Then
                    Do
                        $SelAddr = _GUICtrlListBox_GetSelItems($lbxAddresses)
                        If $SelAddr[0] > 0 Then
                            $Cnt = 0
                            _GUICtrlListBox_DeleteString($lbxAddresses, $SelAddr[1])
                        Else
                            $Cnt = 1
                        EndIf
                    Until $Cnt = 1
                EndIf
            EndIf
        Case $lbxAddresses
            ;No action needed
        Case $cmdSend
            ;Send email
            $SelAddr = _GUICtrlListBox_GetSelItemsText($lbxAddresses)
            If $SelAddr[0] = 0 Then
                MsgBox(16, $appName, "Error - No recipient entered...")
                $OkToSend = False
            ElseIf $SelAddr[0] = 1 Then
                $eTo = $SelAddr[1]
            Else
                $eTo = $SelAddr[1]
                For $i = 2 To $SelAddr[0]
                    $eTo = $eTo & "; " & $SelAddr[$i]
                Next
            EndIf
            $eSubj = GUICtrlRead($txtSubject) ; How to use ControlIDs <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $eBody = GUICtrlRead($txtMsg)     ; How to use ControlIDs <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            MsgBox(0, "", $eBody)
            If $OkToSend = True Then SendEmail($eTo, $eSubj, $eBody)
            If $Res = True Then
                ControlSetText("", "", 3, "Sent Ok...")
                Sleep(2000)
                ControlSetText("", "", 3, "Send")
            EndIf
    EndSwitch
WEnd
;-------------------------------------------------------
Func SendEmail($eTo, $eSubj, $eBody)
    Local $olMailItem = 0
    Local $olByValue = 1
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem($olMailItem)
    ;$oOMail.Save
    With $oOMail
        .To = $eTo
        .Subject = $eSubj
        .HTMLBody = $eBody
        .BodyFormat = 2;Plain=1, HTML=2, RichText=3
        .Importance = 1;Low=0, Normal=1, High=2
        .Send
    EndWith
    $oOApp = 0
    $Res = True
EndFunc   ;==>SendEmail
;-------------------------------------------------------
Func ReadiniFile()
    $File = FileOpen("eMailer.ini", 0)
    If $File = -1 Then
        MsgBox(64, $appName, "No addresses file exists. A new one will be created.")
    Else
        While 1
            $Line = FileReadLine($File)
            If @error = -1 Then ExitLoop
            _GUICtrlListBox_AddString($lbxAddresses, $Line)
        WEnd
        FileClose($File)
    EndIf
EndFunc   ;==>ReadiniFile
;-------------------------------------------------------
Func WriteiniFile()
    $File = FileOpen("eMailer.ini", 2)
    $Cnt = _GUICtrlListBox_GetCount($lbxAddresses)
    If $Cnt > 0 Then
        For $i = 0 to ($Cnt - 1)
            $Line = _GUICtrlListBox_GetText($lbxAddresses, $i)
            FileWriteLine($File, $Line & @CRLF)
        Next
    EndIf
    FileClose($File)
EndFunc   ;==>WriteiniFile

I am afraid I cannot help with the missing @CRLFs once they leave AutoIt as I do not have OutLook - but have you tried different settings for the .BodyFormat parameter? :mellow:

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
gfcaim

That's excellent - I understand now :mellow:

Thanks so much.

Edited by gfcaim

[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
koresho

I've got a question related to this topic, possibly.

I'm trying to create a multiline edit control and add text to it (kind of like a live log file). I want each new text entry to create a new line and the entire edit to scroll.

However, when I add more text to the Edit, the @CRLF's in my strings become [] boxes, and the script adds these on the same line!

Any ideas?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_DLGFRAME)
$dldirtext = GUICtrlCreateInput("", 10, 10, 280, 180,$ES_READONLY)
GUISetState()
GUICtrlSetData($dldirtext, 'File: Blah.txt Skipped' & @CRLF, "add")
Sleep(2000)
GUICtrlSetData($dldirtext, 'File: Blah2.txt Skipped' & @CRLF, "add")
Sleep(2000)
GUICtrlSetData($dldirtext, 'File: Blah3.txt Copied' & @CRLF, "add")
Sleep(2000)

Share this post


Link to post
Share on other sites
gfcaim

I changed your 'Input' to an 'Edit'. I think the Input was not set to multi-line, hence displaying the ascii placeholders...

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_DLGFRAME)
$dldirtext = GUICtrlCreateEdit("", 10, 10, 280, 180,$ES_READONLY)
GUISetState()
GUICtrlSetData($dldirtext, "File: 1 Skipped" & @CRLF, "add")
Sleep(2000)
GUICtrlSetData($dldirtext, 'File: 2 Skipped' & @CRLF, "add")
Sleep(2000)
GUICtrlSetData($dldirtext, 'File: 3 Copied' & @CRLF, "add")
Sleep(2000)

[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
Melba23

gfcaim,

I think the Input was not set to multi-line

Good guess - Input control are indeed Edit controls forced to single line mode! :mellow:

koresho,

You have your answer from gfcaim. :party:

By the way, did you intend for your window to be reversed for right-to-left text? :P

If so, you did it the wrong way - this is the accepted way:

$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_EX_LAYOUTRTL)

If not, then you had the $WS_DLGFRAME style in the extended style parameter place - and the values happened to be the same: :party:

; You had:
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_DLGFRAME)

; You should have used:
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, $WS_DLGFRAME)

I hope that is clear. :party:

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
gfcaim

Should anyone have the same issue that I had in the original post (multi-line working ok until emailed, then showing on one line) then the solution was to change '.HTMLBody' to '.Body' and that works fine then :mellow:

So the code is now:

Func SendEmail($eTo,$eSubj,$eBody)
    Local $olMailItem = 0
    Local $olByValue = 1
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    With $oOMail
        .To = $eTo
        .Subject = $eSubj
        .Body = $eBody
        .BodyFormat = 2;Plain=1, HTML=2, RichText=3
        .Importance = 1;Low=0, Normal=1, High=2
        .Send
    EndWith
    $oOApp=0
    $Res = true
EndFunc

Next question... why doesn't '_GUICtrlListBox_SetCurSel($lbxAddresses,-1)' de-select my listbox selections as it should (as mentioned in the help file)?


[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
gfcaim

Next question... why doesn't '_GUICtrlListBox_SetCurSel($lbxAddresses,-1)' de-select my listbox selections as it should (as mentioned in the help file)?

I have achieved this with:

_GUICtrlListBox_SelItemRange ($lbxAddresses,0,_GUICtrlListBox_GetCount($lbxAddresses),False)

but not sure if that is the correct way?...


[font="Comic Sans MS"]"I'm not usually a praying man, but if you are up there, please save me Superman!" (Homer J. Simpson)[/font]

Share this post


Link to post
Share on other sites
koresho

I changed your 'Input' to an 'Edit'. I think the Input was not set to multi-line, hence displaying the ascii placeholders...

koresho,

You have your answer from gfcaim. :P

By the way, did you intend for your window to be reversed for right-to-left text? :mellow:

If so, you did it the wrong way - this is the accepted way:

$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_EX_LAYOUTRTL)

If not, then you had the $WS_DLGFRAME style in the extended style parameter place - and the values happened to be the same: :party:

; You had:
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, -1, $WS_DLGFRAME)

; You should have used:
$dldirgui = GUICreate("Downloading folder:", 300, 200, -1, -1, $WS_DLGFRAME)

I hope that is clear. :party:

M23

Thanks so much for the replies... I sure feel unobservant now. No, I didn't mean to have the text right-justified, I had planned to find out why this was happening when I started working on it today but you beat me to it :party:

Thanks again for the help, both of you. And sorry for semi-derailing the topic.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.