Jump to content

Edit box - how can I delete lines?


enaiman
 Share

Recommended Posts

The matter of the limit of the edit box has been discussed several times on this forum (found related topics and read them) but I wasn't able to find a solution.

I use an edit box to display what is sent/received over a serial connection - the problem is the edit box is filling very fast.

My idea is to make something like a "buffer" or to make the edit control to automatically delete the "extra" lines over my limit (I want to limit its size at 250 lines and the text in it to roll untill the end of transmission occurs)

I had a look at GuiEdit.au3 and found something: _GUICtrlEditSetSel and _GUICtrlEditReplaceSel so I thought this solution will work:

If _GUICtrlEditGetLineCount($Edit2) > $edit_limlines Then   ;if the number of lines is greater than the limit
                _GUICtrlEditSetSel($Edit2, 0, 20)    ;selects 20 lines of text
                _GUICtrlEditReplaceSel($Edit2, False, "")   ;replaces them with nothing ""
            EndIf

It works but it has an "undesired" effect: whenever something is selected the text scrolls automatically up, then down and the result is looking "ugly".

How can this be done? - I mean deleting lines from an edit control?

Thank you,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

What are you capturing the serial data into? A file, string, array, straight into the edit control...?

My thought is that you should be able to just pull the first (or last) n lines of data and update the Edit control with them. Complex management of the Edit control itself is just not required.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The data is captured in a string - once the string is received it is used to update the edit control (add it to existing content).

It might be a good idea to use an array and delete always the first elements before adding new ones.

... it is a new way to do it and I'll have to rewrite/rethink a part of my script :) ... but at least it would be better ... hope so ...

It is amazing how a single word sometimes can generate so many ideas <_<

Thanks,

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

The data is captured in a string - once the string is received it is used to update the edit control (add it to existing content).

It might be a good idea to use an array and delete always the first elements before adding new ones.

... it is a new way to do it and I'll have to rewrite/rethink a part of my script :P ... but at least it would be better ... hope so ...

It is amazing how a single word sometimes can generate so many ideas <_<

Thanks,

One of your many options is to keep it in the string and use StringInStr() to get the first (or last, not sure what you want) lines. For example, use the Occurrence option to get the location of the 10th (or -10th from the end) occurrence of @LF, then get just that portion (demo needs tweaking if the delimiter is not @LF):

#include <array.au3> ; Only for _ArrayDisplay()

$sInput = "Line 1" & @LF & "Line 2" & @LF & "Line 3" & @LF & "Line 4" & @LF & "Line 5" & @LF & "Line 6" 

$avOutput = _GetFirstOrLastLines($sInput, 3)
_ArrayDisplay($avOutput, "First 3 lines")

$avOutput = _GetFirstOrLastLines($sInput, -4)
_ArrayDisplay($avOutput, "Last 4 lines")

$avOutput = _GetFirstOrLastLines($sInput, 8)
_ArrayDisplay($avOutput, "First 8 lines")

$avOutput = _GetFirstOrLastLines($sInput, -12)
_ArrayDisplay($avOutput, "Last 12 lines")

Func _GetFirstOrLastLines($sIn, $iOccurrence)
    Local $iIndex, $sOut
    
    $sIn = StringStripWS($sIn, 1 + 2)
    $iIndex = StringInStr($sIn, @LF, 0, $iOccurrence)
    If $iOccurrence > 0 Then
        If $iIndex = 0 Then
            $sOut = $sIn
        Else
            $sOut = StringLeft($sIn, $iIndex - 1)
        EndIf
    Else
        $sOut = StringRight($sIn, StringLen($sIn) - $iIndex)
    EndIf
    
    Return StringSplit($sOut, @LF)
EndFunc   ;==>_GetFirstOrLastLines

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thank you PsaltyDS for your help - I'm sure it will prove useful to me (I'm not up to that part yet because I have to "refigure" how to properly format the array; my switch is sending back alot of CRLF and I need to develop an algorythm to eventually get rid of extra blank lines while keeping the display accurate)

I guess I will send a PM to martin asking him kindly for help (I'm using his UDF)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Thank you PsaltyDS for your help - I'm sure it will prove useful to me (I'm not up to that part yet because I have to "refigure" how to properly format the array; my switch is sending back alot of CRLF and I need to develop an algorythm to eventually get rid of extra blank lines while keeping the display accurate)

I guess I will send a PM to martin asking him kindly for help (I'm using his UDF)

StringStripWS() with option 4 will remove multiple whitespace characters like @CRLF.

This could be a problem if you need to preserve multiple @TABs or spaces, though.

To target only the multi-@CRLF strings do a loop like this:

#include <array.au3> ; Only for _ArrayDisplay()

$sInput = @CRLF & @CRLF & "Line 1" & @CRLF & @CRLF & "Line 2" & @CRLF & @CRLF & @CRLF & "Line 3" & @CRLF & "Line 4" & _
        @CRLF & @CRLF & "Line 5" & @CRLF & "Line 6" & @CRLF & @CRLF 
        
_ArrayDisplay(StringSplit($sInput, @CRLF, 1), "Before")

Do
    $sInput = StringReplace($sInput, @CRLF & @CRLF, @CRLF) ; replace every double with a single
Until @extended = 0
$sInput = StringStripWS($sInput, 1+2) ; strip leading and trailing WS

_ArrayDisplay(StringSplit($sInput, @CRLF, 1), "After")

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I figured how to get everything in an array / string and how to make it to keep only the line ammount I need.

Now it cames back to my OP ... <_<

I still have to find a way to refresh the info in my edit control without looking "ugly".

I'm thinking also if there is a way to display a text file in my GUI, and to use that file to store the text received - this way I won't be limited by an edit control (something like a text viewer).

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I figured how to get everything in an array / string and how to make it to keep only the line ammount I need.

Now it cames back to my OP ... :)

I still have to find a way to refresh the info in my edit control without looking "ugly".

I'm thinking also if there is a way to display a text file in my GUI, and to use that file to store the text received - this way I won't be limited by an edit control (something like a text viewer).

Post a working short reproducer script of how the "ugly" version looks.

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 9 years later...

i know, is too late, but my simplified version for this problem is:

;also remember includes

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <GuiEdit.au3>

func writeLog($message)    ;Function for write in a edit

      ;write in the last position (append in last lline)

;
      _GUICtrlEdit_AppendText($edit, String(_NowTime())&" - "&$msg&@CRLF)


      If _GUICtrlEdit_GetLineCount($logBtMsg) > 101 Then   ;se atingir este limite de linhas
         $linha= _GUICtrlEdit_LineIndex($logBtMsg,51)    ;pega a posição e o numero da linha DEIXA NO EDIT AS ULTIMAS 51 LINHAS
         _GUICtrlEdit_SetSel($logBtMsg, 0, $linha)    ;seleciona do inicio até o fim da linha selecionada
         _GUICtrlEdit_ReplaceSel($logBtMsg, "", False)   ;apaga
      EndIf


   EndFunc

Link to comment
Share on other sites

1 minute ago, darckmatrix said:

i know, is too late, but my simplified version for this problem is:

;also remember includes

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <Date.au3>
#include <GuiEdit.au3>

func writeLog($message)    ;Function for write in a edit

                                                   ;write in the last position (append in last lline)
      _GUICtrlEdit_AppendText($edit, String(_NowTime())&" - "&$msg&@CRLF)


      If _GUICtrlEdit_GetLineCount($edit) > 101 Then   ;line limite 100
         $line= _GUICtrlEdit_LineIndex($edit,51)    ;goto line 50, get characters of this line
         _GUICtrlEdit_SetSel($edit, 0, $linha)    ;select from 0 to last character of line 50
         _GUICtrlEdit_ReplaceSel($edit, "", False)   ;clear all between line 0 to 50
      EndIf


   EndFunc

;sorry for my bad english

 

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