Jump to content

Edit Box Help


Recommended Posts

Ok , I want to remove all dead lines from an edit box. I have put all the lines in an array. Now when using _ArrayDelete() it deletes the string properly but also removes the last line do to that the array did not correct itself by changing numbers.

Dim $templine[_GUICtrlEdit_GetLineCount($Edit1) - 1]
    For $tem = 0 To _GUICtrlEdit_GetLineCount($Edit1) - 2 Step 1
        $templine[$tem] = _GUICtrlEdit_GetLine($Edit1, $tem)
        If $templine[$tem] = "" Then _ArrayDelete($templine[$tem], "")
    Next
    GUICtrlSetData($Edit1, _ArrayToString($templine, @CRLF))
Link to comment
Share on other sites

Hi, I used the _GUICtrlEdit_GetText() example from the help file and added StringSplit() and StringStripWS() loop to filter the lines.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiEdit.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$Debug_Ed = False

_Main()

Func _Main()
    Local $hEdit

    ; Create GUI
    GUICreate("Edit Get Text", 400, 300)
    $hEdit = GUICtrlCreateEdit("", 2, 2, 394, 268)
    GUISetState()

    ; Set Text
    _GUICtrlEdit_SetText($hEdit, "This is a test" & @CRLF & "Another Line" & @CRLF & "Append to the end?" & _
    @CRLF & @CRLF & "So a needle pulling thread" & @CRLF & @CRLF & "Another Line" & @CRLF & "Append to the end?" & _
    @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & "Last line of gibberish.")
    
    ;Strip blank lines
    Local $sTmp, $aTmp = StringSplit(_GUICtrlEdit_GetText($hEdit), @CRLF)
    For $i = 1 To $aTmp[0]
        If StringStripWS($aTmp[$i], 8) <> "" Then $sTmp &= StringStripWS($aTmp[$i], 2) & @CRLF
    Next
    MsgBox(4160, "Striped of blank lines", StringStripWS($sTmp, 2))
    _GUICtrlEdit_SetText($hEdit, StringStripWS($sTmp, 2))
    
    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Cheers

Edited by smashly
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...