Jump to content

Cut Function?


BrettF
 Share

Recommended Posts

How can I Cut text from a selected portion of an edit box??

I have tried this:

$cuter = _GUICtrlEditGetSel ($edit1)
            ClipPut (_GUICtrlEditSetSel ( $edit1, $cuter[1], $cuter[2]) )
            _GUICtrlEditReplaceSel ($edit1,1,"")

But it didnt word :)

Thanks

Bert

Link to comment
Share on other sites

Here's a small example that was slightly modified from the helpfile:

;This will move over the users selected text by 1.
#include <GUIConstants.au3>
#include <GuiEdit.au3>

opt('MustDeclareVars', 1)

Dim $myedit, $Status, $msg, $Btn_GET, $a_sel

GUICreate("Edit Get Line Count", 392, 254)

$myedit = GUICtrlCreateEdit("First line" & @CRLF, 140, 32, 121, 97, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE))
GUICtrlSetLimit($myedit, 1500)
$Status = GUICtrlCreateLabel("", 0, 234, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))
$Btn_GET = GUICtrlCreateButton("Get Sel", 150, 130, 90, 40, $BS_MULTILINE)

; will be append dont' forget 3rd parameter
GUICtrlSetData($myedit, "2nd line" & @CRLF & "3rd line" & @CRLF & "4th line" & @CRLF & _
        "5th line" & @CRLF & "6th line" & @CRLF & "7th line" & @CRLF & "8th line" & @CRLF & "9th line", 1)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Btn_GET
            $a_sel = _GUICtrlEditGetSel ($myedit)
            If ($a_sel == $EC_ERR) Then
                GUICtrlSetData($Status, "Error getting sel positions")
            ElseIf (IsArray($a_sel)) Then
                GUICtrlSetData($Status, "Starting Pos: " & $a_sel[1] & " Ending Pos: " & $a_sel[2])
                GUICtrlSetState($myedit, $GUI_FOCUS) ; keeps the focus on $myedit
                _GUICtrlEditSetSel($myedit, $a_sel[1]+1, $a_sel[2]+1) ; moves it over by 1
            Else
                GUICtrlSetData($Status, "")
            EndIf
    EndSelect
WEnd

As you can see, _GUICtrlEditGetSel() returns NUMBERS of the starting and ending position of the selected text. What we did in this example is take those numbers, add 1 to each, and set the sel to the new starting and ending position.

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

I think I'm confusing myself :">

Still dosn't help. :) All i want to happen is the selected text from the editbox to be copied to the clipboard. Kurt's example is great, except i cannot figure out how to use it.

Forget the cut part. Just the copy.

Thanks Bert.

Link to comment
Share on other sites

  • Moderators

I think I'm confusing myself :">

Still dosn't help. :) All i want to happen is the selected text from the editbox to be copied to the clipboard. Kurt's example is great, except i cannot figure out how to use it.

Forget the cut part. Just the copy.

Thanks Bert.

Edit:

Man, I need to keep up, never even noticed:

_GUICtrlEditGetSel()

Edit2:

Local $WholeEdit = GUICtrlRead($myedit)
Local $Trim = StringLeft(StringTrimLeft($WholeEdit, $a_sel[1]), $a_sel[2] - $a_sel[1])
ClipPut($Trim)
Be sure to look at $Trim. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I seriously love you right now. SmokeN your my hero! :D:) lol Thanks heaps. I'll create a udf that does that now :D

Func _GUICtrlEditReadSel($nCID)
    Local $aSel = _GUICtrlEditGetSel($nCID)
    If $aSel = -1 Then Return SetError(1, 0, -1)
    Return StringMid(GUICtrlRead($nCID), $aSel[1] + 1, ($aSel[2] - $aSel[1]) + 1)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...