Jump to content

Edit control has 30000 character limit


Recommended Posts

It looks like the default Edit control maximum character limit is 30000 characters.

Is there a systematic way to delete the oldest line to give room for the newest line in that 30000 character buffer? I didn't find any functions specific for this and thought doing stuff like sending CTRL+HOME, SHIFT+PGDN, DEL, CTRL+END would be kind of cheezy.

I don't really want to continually increase the maximum text length. This will mostly be for a short status history thing for a GUI front end. It's ok if the oldest messages are lost because these same messages will be getting recorded to a file.

Here is a sample (the deleting stuff would replace the commented out text):

#include <GUIConstants.au3>
#include <GuiEdit.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Scripts\BannerPerformanceTracker\Backups\MemoryLeakThingie.kxf
$Form1 = GUICreate("Form1", 1024, 447)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("Spam ON", 2, 2, 101, 25, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
$Edit1 = GUICtrlCreateEdit("", 2, 28, 1019, 415, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))
GUICtrlSetData(-1, "_GUICtrlEdit_GetLimitText: " & _GUICtrlEdit_GetLimitText($Edit1))
$Button2 = GUICtrlCreateButton("Spam OFF", 112, 2, 101, 25, 0)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetData($Edit1, @CRLF & @ScriptName & " started.  Line: " & @ScriptLineNumber, 1)

Local $spam = 0

While 1
    Sleep(100)
   
    If $spam = 1 Then
        If(_GUICtrlEdit_GetTextLen($Edit1) > (_GUICtrlEdit_GetLimitText($Edit1) * .90)) Then
            ;### Need code here to get rid of a few lines from oldest strings in edit box... ###
        EndIf
        Blah("_GUICtrlEdit_GetTextLen: " & _GUICtrlEdit_GetTextLen($Edit1) & _
            " - SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM")
    EndIf
WEnd

Func Blah($text)
    _GUICtrlEdit_AppendText($Edit1, @CRLF & $text)
EndFunc

Func Button1Click()
    $spam = 1
EndFunc
Func Button2Click()
    $spam = 0
EndFunc
Func Form1Close()
    Exit
EndFunc

Thanks! :)

Link to comment
Share on other sites

This does seem to work, but I don't think it is the optimal solution:

ControlSend($appTitle, "", $Edit1, "^{HOME}+{PGDN}{DEL}^{END}")
Confirmed the above code is bad... A few minutes of running that while working on other stuff caused rogue "send" keystrokes in code I was working on causing a lot of it to be deleted :)
Link to comment
Share on other sites

Confirmed the above code is bad... A few minutes of running that while working on other stuff caused rogue "send" keystrokes in code I was working on causing a lot of it to be deleted ;)

Lol... I think I just figured it out.

GUICtrlSetData($Edit1, StringRight(_GUICtrlEdit_GetText($Edit1), 25000))

Sorry for the quick post, replies and fix. Maybe this will help someone out at least? :)

Link to comment
Share on other sites

  • 10 years later...

A long time after...

Here is the solution I implemented as a workaround:

do  ; manage control content maximum size = 32767 (plain text)
        local $sCtlTxt = _GUICtrlRichEdit_GetText($_DbgConsoleCtlId)    ; get full content in control as plain text
        if StringLen($sCtlTxt)+StringLen($sText) <= 32767 then exitloop ; no need to remove any text from control
        local $iVT = StringInStr($sCtlTxt, Chr(11))                     ; search position of first newline character
        if ($iVT == 0) then $iVT = 80                                   ; if no newline char found, arbitrarily cut 80 chars
        if ($iVT > StringLen($sCtlTxt)) then $iVT = StringLen($sCtlTxt) ; make sure $iVT does not exceed text size
        _GUICtrlRichEdit_SetSel($_DbgConsoleCtlId, 0, $iVT)             ; select control text from starting char to newline char
        _GUICtrlRichEdit_ReplaceText($_DbgConsoleCtlId, "", false)      ; remove selected text
    until (false)
    local $sRTF = AnsiToRTF($sText, "Arial", $sColor, 9, $bBold)        ; convert $sText to RTF
    _GUICtrlRichEdit_AppendText($_DbgConsoleCtlId, $sRTF)               ; append $sRTF at end of widget content

 

Link to comment
Share on other sites

  • Melba23 locked and unlocked this topic

@SharpDressedMan : now that you revived it...
To bypass the 30.000 characters limitation, this should do it, for example 200.000 characters :

_GUICtrlEdit_SetLimitText($hWnd, 200000)

It will work with all 3 Edit controls, created by :
GUICtrlCreateEdit()
_GUICtrlEdit_Create()
_GUICtrlRichEdit_Create()

In case of GUICtrlCreateEdit(), it's not a problem if you pass the control id only, because the function _GUICtrlEdit_SetLimitText() will convert it to its handle.

Edit  : if you want an unlimited size :

_GUICtrlEdit_SetLimitText($hWnd, -1)

MSDN : "If cchMax is set to -1, the multiline edit control limit is 0x7FFFFFFE" (i think it's 2.147.483.646 characters !) . Just tested it on a 2Mb text file... it worked (test = paste the 2Mb characters in the control, empty clipboard, copy it from the control, paste it in a new file, compare with the original)

Hope it will help AutoIt members struggling with the 30.000 characters limitation in Edit controls :)

Edited by pixelsearch
Link to comment
Share on other sites

  • Moderators

pixelsearch,

Please note that the OP was NOT a request to increase the size of the edit content - in fact that was specifically excluded as a solution:

Quote

I don't really want to continually increase the maximum text length

The whole thread is about stripping text from the top of the edit content so that the overall length does not become excessive.

Nothing wrong with what you posted - except that it does not answer the OP! First lesson in examination technique - read the question!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Also, the thread is nearly 11 years old at this point and the OP hasn't been here in 3 years.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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