Jump to content

Limit List lines...


Recommended Posts

Hello

how can i limit the amount of lines a list can hold ?

i am using a list in my project to show logs.

the list eventually will show thousands of lines, i want to limit the amount of lines to avoid any crash or slow performance , as we only need to see the last 50 or so logs 

i tried this but no luck

 

$listLog = GUICtrlCreateList("", 0, 400, @DesktopWidth/2 -460,200,0x1000)
GUICtrlSetLimit($listLog, 3)
GUISetState(@SW_SHOW)

 

Link to comment
Share on other sites

  • Moderators

fraizor,

Read the number of items in the list with _GUICtrlListBox_GetCount and, if it is over the required maximum, use _GUICtrlListBox_DeleteString to delete the early lines.

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

GUICtrlSetLimit only limits the horizontal scrolling.
You have to use GUICtrlSetData to fill the list. Simply stop adding new entries when your limit has been reached.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Here an example how to use ControlCommand to interact with a ListBox :

#include <GUIConstants.au3>
#include <Constants.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

  Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
  Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
  Local $idMylist = GUICtrlCreateList("Buttons that have been clicked by number", 176, 32, 150, 120, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL))
  GUICtrlSetLimit(-1, 300) ; to limit horizontal scrolling
  GUICtrlSetData(-1, "The following buttons have been clicked")
  Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

  GUISetState(@SW_SHOW)

  Local $iNum = 0, $iCount
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idButton_Close
        ExitLoop
      Case $idButton_Add
        $iCount = ControlCommand($hGUI, "", $idMylist, "GetCount")
        If $iCount > 10 Then ControlCommand($hGUI, "", $idMylist, "DelString", 0)
        $iNum += 1
        GUICtrlSetData($idMylist, "You clicked button No " & $iNum & "|")
        ControlCommand($hGUI, "", $idMylist, "SetCurrentSelection", $iCount > 10 ? 10 : $iCount)
      Case $idButton_Clear
        GUICtrlSetData($idMylist, "")
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

Link to comment
Share on other sites

24 minutes ago, Nine said:

Here an example how to use ControlCommand to interact with a ListBox :

#include <GUIConstants.au3>
#include <Constants.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

  Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
  Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
  Local $idMylist = GUICtrlCreateList("Buttons that have been clicked by number", 176, 32, 150, 120, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL))
  GUICtrlSetLimit(-1, 300) ; to limit horizontal scrolling
  GUICtrlSetData(-1, "The following buttons have been clicked")
  Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

  GUISetState(@SW_SHOW)

  Local $iNum = 0, $iCount
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idButton_Close
        ExitLoop
      Case $idButton_Add
        $iCount = ControlCommand($hGUI, "", $idMylist, "GetCount")
        If $iCount > 10 Then ControlCommand($hGUI, "", $idMylist, "DelString", 0)
        $iNum += 1
        GUICtrlSetData($idMylist, "You clicked button No " & $iNum & "|")
        ControlCommand($hGUI, "", $idMylist, "SetCurrentSelection", $iCount > 10 ? 10 : $iCount)
      Case $idButton_Clear
        GUICtrlSetData($idMylist, "")
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

thank you for the example , i am getting this error ...

image.thumb.png.73503197b76f5def2fae4a638bcb22b5.png

Link to comment
Share on other sites

Replace "GetCount" wiht "GetLineCount".

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Does the script work for you? Means: Press the "Add" button until you see > 10 lines.
Here the script does not delete lines.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Seems that "GetLineCount" does not work for a ListBox.
I modified the script and it now works for me:

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

  Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
  Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
  Local $idMylist = GUICtrlCreateList("Buttons that have been clicked by number", 176, 32, 150, 120, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL))
  GUICtrlSetLimit(-1, 300) ; to limit horizontal scrolling
  GUICtrlSetData(-1, "The following buttons have been clicked")
  Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

  GUISetState(@SW_SHOW)

  Local $iNum = 0, $iCount
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idButton_Close
        ExitLoop
      Case $idButton_Add
        ; $iCount = ControlCommand($hGUI, "", $idMylist, "GetLineCount")
        $iCount = _GUICtrlListBox_GetCount($idMyList)
        ConsoleWrite("$iCount: " & $iCount & ", @error=" & @error & @CRLF)
        If $iCount >= 10 Then
            ; ControlCommand($hGUI, "", $idMylist, "DelString", 1)
            _GUICtrlListBox_DeleteString ($idMylist, 0)
            ConsoleWrite("ControlCommand: @error=" & @error & @CRLF)
        EndIf
        $iNum += 1
        GUICtrlSetData($idMylist, "You clicked button No " & $iNum & "|")
        ControlCommand($hGUI, "", $idMylist, "SetCurrentSelection", $iCount > 10 ? 10 : $iCount)
      Case $idButton_Clear
        GUICtrlSetData($idMylist, "")
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

2 minutes ago, water said:

Does the script work for you? Means: Press the "Add" button until you see > 10 lines.
Here the script does not delete lines.

yes it seems to work for me , all buttons are working , however my auto scroll question is in general. 

this is a sample code.. how can i make it always show the last line ? 

GUICreate("", 500, 600)
$listLog = GUICtrlCreateList("", 0, 400, @DesktopWidth/2 -460,200)

GUISetState(@SW_SHOW)
for $i = 0 to 90
    GUICtrlSetData($listLog,@SEC & "|")
    Sleep(500)
next

 

image.png.4e073fc767e62320975c431cbc63f410.png

Link to comment
Share on other sites

This works perfect here:

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>

Example()

Func Example()
    Local $hGUI = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered
    Local $iMaxItems = 10

    Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    Local $idMylist = GUICtrlCreateList("Buttons that have been clicked by number", 176, 32, 150, 120, BitOR($WS_BORDER, $WS_VSCROLL, $WS_HSCROLL))
    GUICtrlSetLimit(-1, 300) ; to limit horizontal scrolling
    GUICtrlSetData(-1, "The following buttons have been clicked")
    Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState(@SW_SHOW)

    Local $iNum = 0, $iCount
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop
            Case $idButton_Add
                $iCount = _GUICtrlListBox_GetCount($idMylist)
                If $iCount >= $iMaxItems Then
                    _GUICtrlListBox_DeleteString($idMylist, 0)
                    $iCount = $iCount - 1
                EndIf
                $iNum += 1
                GUICtrlSetData($idMylist, "You clicked button No " & $iNum & "|")
                _GUICtrlListBox_SetCurSel($idMylist, $iCount)
                $iCount = $iCount + 1
            Case $idButton_Clear
                GUICtrlSetData($idMylist, "")
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Link to comment
Share on other sites

My version runs and works with AutoIt 3.3.14.5

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

As posted above: The parameter for ControlCommand was wrong. Has to be changed from "GetCount" to "GetLineCount".
In addition

$iCount = ControlCommand($hGUI, "", $idMylist, "GetLineCount")

always returned 0. According to the help file: "Returns # of lines in an Edit". So GetLineCount does not seem to work for a ListBox control (at least in 3.3.14.5.).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

3 minutes ago, water said:

Has to be changed from "GetCount" to "GetLineCount".

I do not have 3.3.14.5 anymore but according to 3.3.16.0 documentation of ControlCommand :

 

Quote
"GetCount", ""     Returns number of entries in a ListBox or ComboBox

Where 

Quote
option [optional]    Additional parameter required by some commands.

So with 3.3.16.0

$iCount = ControlCommand($hGUI, "", $idMylist, "GetCount")

The code is working perfectly and you do not have to specify the option parameter.  I guess it is time to update ;)

Link to comment
Share on other sites

Keyword "GetCount" does not exist in AutoIt 3.3.14.5 and was added with 3.3.16.0 in March 2022.
I let a few months pass before I update to the latest version :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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