Jump to content

Problems with EditBox


DarkwarlorD
 Share

Recommended Posts

A while ago I posted a problem that was solved brilliantly, and now came another question ... How do I organize a selection made in a EditBox?

Excuse my mistakes, English is not my native language.

What do you want to do with the selected text in an edit? Organize doesn't make sensde to me. Do you mean you want to copy the selected text? Or do you mean you want to change it somehow?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Sorry, I will explain:

I have a EditBox, and want, making the selection of a portion of the text, I click on a button and the text is categorized according to the first letter.

Indeed my EditBox I used to keep a list of what I want and I have.

Thank you for your attention.

Link to comment
Share on other sites

Sorry, I will explain:

I have a EditBox, and want, making the selection of a portion of the text, I click on a button and the text is categorized according to the first letter.

Indeed my EditBox I used to keep a list of what I want and I have.

Thank you for your attention.

Mmmh.

I understand only some of that.

You have an edit box

You select some of the text

You click a button

then the next bit I don't understand

the text is categorized according to the first letter.

Can you give an example of the text, and show the selected section in bold or a different colour, then show how the text should look after the button is pressed?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Of course. Example:

They are classified / organised by the first letter.

Sorry for the awful English.

Ok I underrstand that the list you have shopwn is arranged alphabetically.

Do you have a lot of text in the edit and you want to select just a portion of that text and have the selected portion rearranged alphabetically?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

But I want to add more items.

My idea is a Control of Animes, where I add and arrange alphabetically.

I don't know the answer to my question so I've assumed you only want to sort the selected items.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <guiedit.au3>
#include <array.au3>
#include <EditConstants.au3>

Opt('MustDeclareVars', 1)


Example()

Func Example()
    Local $myedit, $msg, $but, $range, $sel, $asel, $n
    Local $line1, $line2, $temp, $newstart, $newend, $line2end, $line2len

    GUICreate("My GUI edit", 500, 500); will create a dialog box that when displayed is centered

    $myedit = GUICtrlCreateEdit("First line" & @CRLF, 10, 20, 421, 437, BitOR($ES_WANTRETURN, $ES_AUTOVSCROLL, $WS_VSCROLL))
    $but = GUICtrlCreateButton("sort selected text", 100, 470, 120, 22)
    GUISetState()

    Send("{END}")

; will be append dont' forget 3rd parameter
    GUICtrlSetData($myedit, "bannana" & @CRLF, 1)
    GUICtrlSetData($myedit, "peaches" & @CRLF, 1)
    GUICtrlSetData($myedit, "apples" & @CRLF, 1)
    GUICtrlSetData($myedit, "oranges" & @CRLF, 1)
    GUICtrlSetData($myedit, "wallnuts" & @CRLF, 1)
    GUICtrlSetData($myedit, "marzipan" & @CRLF, 1)
    GUICtrlSetData($myedit, "bread" & @CRLF, 1)

; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        If $msg = $but Then
            $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($myedit))
            If $range[0] <> $range[1] Then
                $line1 = _GUICtrlEdit_LineFromChar(GUICtrlGetHandle($myedit), $range[0])
                $line2 = _GUICtrlEdit_LineFromChar(GUICtrlGetHandle($myedit), $range[1])
                $line2len = StringLen(_GUICtrlEdit_GetLine(GUICtrlGetHandle($myedit), $line2))
                ConsoleWrite($range[0] & @CRLF)
                ConsoleWrite($line1 & ', ' & $line2 & @CRLF)
                $sel = ''
                If $line1 = $line2 Then ContinueLoop
                
                If $line1 > $line2 Then
                    $temp = $line1
                    $line1 = $line2
                    $line2 = $temp
                EndIf
                
;Make sure we change the selection to be from the start of a line to the end of a line in case the operator didn't!
                $newstart = _GUICtrlEdit_LineIndex(GUICtrlGetHandle($myedit), $line1)
                $newend = _GUICtrlEdit_LineIndex(GUICtrlGetHandle($myedit), $line2) + $line2len
                ConsoleWrite("start end (new) = " & $newstart & ', ' & $newend & @CRLF)
                
                Dim $asel[$line2 - $line1 + 1]
                For $n = $line1 To $line2
                    $asel[$n - $line1] = _GUICtrlEdit_GetLine(GUICtrlGetHandle($myedit), $n)
                Next
                _ArraySort($asel)
                $sel = ''
                For $n = 0 To $line2 - $line1
                    $sel &= $asel[$n] & @CRLF
                Next
                $sel = StringLeft($sel, StringLen($sel) - 2)
                ConsoleWrite($sel & @CRLF)
;ensure selection is complete lines before replacing
                _GUICtrlEdit_SetSel(GUICtrlGetHandle($myedit), $newstart, $newend)
                _GUICtrlEdit_ReplaceSel(GUICtrlGetHandle($myedit), $sel)
                
            EndIf
        EndIf
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc ;==>Example

Needs some attention because sometimes it adds a new line at the start but the idea works.

It would be much simpler if you only wanted to sort the whole list.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...