Jump to content

GUICtrlCreateEdit


 Share

Recommended Posts

Does anyone know of the best way to remove the last line in an edit control? I mean, if a user inputs:

Line 1

Line 2

Line 3

How do you remove "line 3" so the control only displays the first 2?

I have tried using StringInStr with StringMid and StringRight, just wondering if there is an easier way than going through every line?

Link to comment
Share on other sites

Does anyone know of the best way to remove the last line in an edit control? I mean, if a user inputs:

Line 1

Line 2

Line 3

How do you remove "line 3" so the control only displays the first 2?

I have tried using StringInStr with StringMid and StringRight, just wondering if there is an easier way than going through every line?

I write a simple example to do what you want:

$GUI = GUICreate("TEST",200,170)
$EDIT = GUICtrlCreateEdit("LINE1" & @CRLF & "LINE2" & @CRLF & "LINE3",5,5,190,100)
$REMOVE = GUICtrlCreateButton("REMOVE LAST LINE",5,120,190,40)
GUISetState()

While 1
    $MSG = GUIGetMsg()
    If $MSG = $REMOVE Then
        $TEMP_DATA = GUICtrlRead($EDIT)
        $TEMP_DATA = StringSplit($TEMP_DATA,@CRLF)
        $NEW_DATA = ""
        For $INDEX = 1 To $TEMP_DATA[0]-1 Step 2
            If $INDEX = $TEMP_DATA[0]-2 Then
                $NEW_DATA &= $TEMP_DATA[$INDEX]
            Else
                $NEW_DATA &= $TEMP_DATA[$INDEX] & @CRLF
            EndIf
        Next
        GUICtrlSetData($EDIT,$NEW_DATA)
    ElseIf $MSG = -3 Then
        Exit
    EndIf
WEnd

When the words fail... music speaks.

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