Jump to content

A way to select a list of items from an Array


Recommended Posts

Usually when I collect data from DataBase I need to give EndUser a possibility to select rows which should be taken in the processing loop.
I was searching on the forum and I'm not able to find any UDF or even example of how to select data from array.
I have my own solutions but I think they are not worth posting on the forum as it is very old code and I am looking for a better solution.

Could anybody point me to some examples/solutions ?

Thank you in advance.
@mLipok

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites

Thanks. Interesting.

I would prefer something like ArrayDisplay which will give you all selected ID's


 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites

Well, I forgot about this magical corner.
There are many examples of displaying data from a database. I have to prepare something ...

I think I will refactor my current function and show it here. Then the conversation will be more precise.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites

As I said this is my old code.... so....
Here is my "some way refactored" code:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

_Example()
Func _Example()
    Local $a_Test[100][10]
    For $ROW = 0 To 99
        For $COL = 0 To 9
            $a_Test[$ROW][$COL] = 'Test #' & $COL
        Next
    Next

    Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', False)
    _ArrayDisplay($a_Selected, '$a_Selected')
EndFunc   ;==>_Example


Func _Array_Select(ByRef $a_Source, $s_title, $s_Information, $b_ArrayHasHeader = True, $hWnd_Parent = 0)
    If Not IsArray($a_Source) Then Return SetError(1, 0, "is not array")

    Local $i_Source_Rows_Count = UBound($a_Source, $UBOUND_ROWS), $i_Source_Cols_Count = UBound($a_Source, $UBOUND_COLUMNS)
    Local $i_Temp_Cols_Count
    If $i_Source_Cols_Count < 0 Then $i_Source_Cols_Count = 0
    If $i_Source_Cols_Count = 0 Then ; If 1D Array
        $i_Temp_Cols_Count = $i_Source_Cols_Count + 1
    Else
        $i_Temp_Cols_Count = $i_Source_Cols_Count
    EndIf

    Local $a_Temp_2[$i_Source_Rows_Count][$i_Temp_Cols_Count]
    If $b_ArrayHasHeader Then
        For $icols = 0 To $i_Temp_Cols_Count - 1
            For $irows = 0 To $i_Source_Rows_Count - 1
                If $i_Source_Cols_Count > 0 Then
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows][$icols]
                Else
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows]
                EndIf
            Next
        Next
    EndIf

    Local $hGuiForm_1 = GUICreate($s_title, 900, 680, 100, -1, -1, -1, $hWnd_Parent)
    GUISetFont(8.5)
    GUICtrlCreateLabel($s_Information, 8, 8, 900, 50)
    Local $id_ListView_1 = GUICtrlCreateListView("", 0, 52, 900, 600, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Local $h_ListView_Wybierz = ControlGetHandle($hGuiForm_1, "", $id_ListView_1)

    Local $id_Button_Select = GUICtrlCreateButton("&Wybierz zaznaczone", 0, 655, 900 - 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Select, 0xA6CAF0)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    Local $id_Button_Cancel = GUICtrlCreateButton("&Anuluj", 900 - 200, 655, 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Cancel, 0xFFFFE1)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW)

    #Region - FillUp ListView
    _GUICtrlListView_BeginUpdate($h_ListView_Wybierz)
    Local $a_Processing
    If $b_ArrayHasHeader Then
        $a_Processing = $a_Temp_2
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][$a])
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][0])
        EndIf
    Else
        $a_Processing = $a_Source
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
        EndIf
    EndIf

    For $id_X_Row = 0 To $i_Source_Rows_Count - 1
        _GUICtrlListView_AddItem($h_ListView_Wybierz, $a_Processing[$id_X_Row][0])
        For $id_X_Col = 0 To $i_Temp_Cols_Count - 1
            _GUICtrlListView_AddSubItem($h_ListView_Wybierz, $id_X_Row, $a_Processing[$id_X_Row][$id_X_Col], $id_X_Col)
        Next
    Next
    _GUICtrlListView_ClickItem($h_ListView_Wybierz, 1, "left", True, 2)
    Send("{CTRLDOWN}{SHIFTDOWN}")
    ControlSend($hGuiForm_1, "", $id_ListView_1, "{NUMPADADD}")
    Send("{SHIFTUP}{CTRLUP}")
    If $b_ArrayHasHeader Then _GUICtrlListView_DeleteItem($h_ListView_Wybierz, 0)
    _GUICtrlListView_EndUpdate($h_ListView_Wybierz)
    #EndRegion - FillUp ListView

    Local $nMsg
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $id_Button_Select
                If _GUICtrlListView_GetSelectionMark($h_ListView_Wybierz) = -1 Then
                    GUIDelete($hGuiForm_1)
                    Return SetError(1, 0, "Nie dokonano wyboru")
                EndIf
                Local $a_Result = StringSplit(_GUICtrlListView_GetSelectedIndices($h_ListView_Wybierz), "|") ; Returns pipe "|" delimited string, "|")
                GUIDelete($hGuiForm_1)
                If $b_ArrayHasHeader Then
                    For $IDX_Choosen = 1 To $a_Result[0] ; zwiększam wartosc o jeden bo wyniki z listview sa mniejsze o jeden w stosunku tablicy poczatkowej
                        $a_Result[$IDX_Choosen] += 1
                    Next
                EndIf
                Return $a_Result
            Case $id_Button_Cancel, $GUI_EVENT_CLOSE
                GUIDelete($hGuiForm_1)
                Return SetError(1, 0, "Nie dokonano wyboru")
        EndSwitch
    WEnd
EndFunc   ;==>_Array_Select

Any ideas for improvement would be appreciated.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites

@mLipok I slightly improved the UI by adding check marks for selection:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

_Example()
Func _Example()
    Local $a_Test[100][10]
    For $ROW = 0 To 99
        For $COL = 0 To 9
            $a_Test[$ROW][$COL] = 'Test #' & $COL
        Next
    Next

    Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', False)
    _ArrayDisplay($a_Selected, '$a_Selected')
EndFunc   ;==>_Example


Func _Array_Select(ByRef $a_Source, $s_title, $s_Information, $b_ArrayHasHeader = True, $hWnd_Parent = 0)
    If Not IsArray($a_Source) Then Return SetError(1, 0, "is not array")

    Local $i_Source_Rows_Count = UBound($a_Source, $UBOUND_ROWS), $i_Source_Cols_Count = UBound($a_Source, $UBOUND_COLUMNS)
    Local $i_Temp_Cols_Count
    If $i_Source_Cols_Count < 0 Then $i_Source_Cols_Count = 0
    If $i_Source_Cols_Count = 0 Then ; If 1D Array
        $i_Temp_Cols_Count = $i_Source_Cols_Count + 1
    Else
        $i_Temp_Cols_Count = $i_Source_Cols_Count
    EndIf

    Local $a_Temp_2[$i_Source_Rows_Count][$i_Temp_Cols_Count]
    If $b_ArrayHasHeader Then
        For $icols = 0 To $i_Temp_Cols_Count - 1
            For $irows = 0 To $i_Source_Rows_Count - 1
                If $i_Source_Cols_Count > 0 Then
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows][$icols]
                Else
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows]
                EndIf
            Next
        Next
    EndIf

    Local $hGuiForm_1 = GUICreate($s_title, 900, 680, 100, -1, -1, -1, $hWnd_Parent)
    GUISetFont(8.5)
    GUICtrlCreateLabel($s_Information, 8, 8, 900, 50)
    Local $id_ListView_1 = GUICtrlCreateListView("", 0, 52, 900, 600, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
    Local $h_ListView_Wybierz = ControlGetHandle($hGuiForm_1, "", $id_ListView_1)

    Local $id_Button_Select = GUICtrlCreateButton("&Wybierz zaznaczone", 0, 655, 900 - 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Select, 0xA6CAF0)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    Local $id_Button_Cancel = GUICtrlCreateButton("&Anuluj", 900 - 200, 655, 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Cancel, 0xFFFFE1)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW)

    #Region - FillUp ListView
    _GUICtrlListView_BeginUpdate($h_ListView_Wybierz)
    Local $a_Processing
    If $b_ArrayHasHeader Then
        $a_Processing = $a_Temp_2
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][$a])
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][0])
        EndIf
    Else
        $a_Processing = $a_Source
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
        EndIf
    EndIf

    For $id_X_Row = 0 To $i_Source_Rows_Count - 1
        _GUICtrlListView_AddItem($h_ListView_Wybierz, $a_Processing[$id_X_Row][0])
        For $id_X_Col = 0 To $i_Temp_Cols_Count - 1
            _GUICtrlListView_AddSubItem($h_ListView_Wybierz, $id_X_Row, $a_Processing[$id_X_Row][$id_X_Col], $id_X_Col)
        Next
    Next
    _GUICtrlListView_ClickItem($h_ListView_Wybierz, 1, "left", True, 2)
    Send("{CTRLDOWN}{SHIFTDOWN}")
    ControlSend($hGuiForm_1, "", $id_ListView_1, "{NUMPADADD}")
    Send("{SHIFTUP}{CTRLUP}")
    If $b_ArrayHasHeader Then _GUICtrlListView_DeleteItem($h_ListView_Wybierz, 0)
    _GUICtrlListView_EndUpdate($h_ListView_Wybierz)
    #EndRegion - FillUp ListView

    Local $nMsg
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $id_Button_Select
                Local $a_Result = StringSplit(_GUICtrlListView_GetCheckedIndices($h_ListView_Wybierz), "|") ; Returns pipe "|" delimited string, "|")
                GUIDelete($hGuiForm_1)
                If $a_Result[0] = 0 Then Return SetError(1, 0, "Nie dokonano wyboru")
                If $b_ArrayHasHeader Then
                    For $IDX_Choosen = 1 To $a_Result[0] ; zwiększam wartosc o jeden bo wyniki z listview sa mniejsze o jeden w stosunku tablicy poczatkowej
                        $a_Result[$IDX_Choosen] += 1
                    Next
                EndIf
                Return $a_Result
            Case $id_Button_Cancel, $GUI_EVENT_CLOSE
                GUIDelete($hGuiForm_1)
                Return SetError(1, 0, "Nie dokonano wyboru")
        EndSwitch
    WEnd
EndFunc   ;==>_Array_Select

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: Damon Harris (TheDcoder) (forked from GetSelectedIndices)
; ===============================================================================================================================
Func _GUICtrlListView_GetCheckedIndices($hWnd, $bArray = False)
    Local $tLVITEM = DllStructCreate($tagLVITEM)
    DllStructSetData($tLVITEM, "Mask", $LVIF_STATE)
    DllStructSetData($tLVITEM, "StateMask", 0xffff)

    Local $sIndices, $aIndices[1] = [0]
    Local $iRet, $iCount = _GUICtrlListView_GetItemCount($hWnd)
    For $iItem = 0 To $iCount
        DllStructSetData($tLVITEM, "Item", $iItem)
        If IsHWnd($hWnd) Then
            $iRet = _SendMessage($hWnd, $LVM_GETITEMW, 0, $tLVITEM, 0, "wparam", "struct*") <> 0
        Else
            $iRet = GUICtrlSendMsg($hWnd, $LVM_GETITEMSTATE, 0, $tLVITEM)
        EndIf
        Local $bChecked = BitAND(DllStructGetData($tLVITEM, "State"), 0x2000) <> 0
        If $bChecked Then
            If (Not $bArray) Then
                If StringLen($sIndices) Then
                    $sIndices &= "|" & $iItem
                Else
                    $sIndices = $iItem
                EndIf
            Else
                ReDim $aIndices[UBound($aIndices) + 1]
                $aIndices[0] = UBound($aIndices) - 1
                $aIndices[UBound($aIndices) - 1] = $iItem
            EndIf
        EndIf
    Next
    If (Not $bArray) Then
        Return String($sIndices)
    Else
        Return $aIndices
    EndIf
EndFunc   ;==>_GUICtrlListView_GetCheckedIndices

I added a new function called _GUICtrlListView_GetCheckedIndices which returns the indexes which are checked from a list view. Credit goes to Gary Frost as I just mashed up two of his functions (_GUICtrlListView_GetSelectedIndices and _GUICtrlListView_GetItemChecked) to create the function:thumbsup:

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to post
Share on other sites

Nice.
But I still prefer to selecting rows instead checking items in the listview.

Here is my improved example:
 

;~ https://www.autoitscript.com/forum/topic/207118-a-way-to-select-a-list-of-items-from-an-array/?tab=comments#comment-1493276

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

_Example(2000, 40)

Func _Example($iRows, $iCols)
    Local $a_Test[$iRows][$iCols]
    For $ROW = 0 To $iRows - 1
        For $COL = 0 To $iCols - 1
            $a_Test[$ROW][$COL] = 'Test long text here #' & $COL
        Next
    Next

    Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', True)
;~  Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', False)
    _ArrayDisplay($a_Selected, '$a_Selected')
EndFunc   ;==>_Example


Func _Array_Select(ByRef $a_Source, $s_title, $s_Information, $b_ArrayHasHeader = True, $hWnd_Parent = 0)
    Local $hTimer = TimerInit()
    If Not IsArray($a_Source) Then Return SetError(1, 0, "is not array")

    Local $i_Source_Rows_Count = UBound($a_Source, $UBOUND_ROWS), $i_Source_Cols_Count = UBound($a_Source, $UBOUND_COLUMNS)
    Local $i_Temp_Cols_Count
    If $i_Source_Cols_Count < 0 Then $i_Source_Cols_Count = 0
    If $i_Source_Cols_Count = 0 Then ; If 1D Array
        $i_Temp_Cols_Count = $i_Source_Cols_Count + 1
    Else
        $i_Temp_Cols_Count = $i_Source_Cols_Count
    EndIf

    Local $a_Temp_2[$i_Source_Rows_Count][$i_Temp_Cols_Count]
    If $b_ArrayHasHeader Then
        For $icols = 0 To $i_Temp_Cols_Count - 1
            For $irows = 0 To $i_Source_Rows_Count - 1
                If $i_Source_Cols_Count > 0 Then
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows][$icols]
                Else
                    $a_Temp_2[$irows][$icols] = $a_Source[$irows]
                EndIf
            Next
        Next
    EndIf

    Local $hGuiForm_1 = GUICreate($s_title, 900, 680, 100, -1, -1, -1, $hWnd_Parent)
    GUISetFont(8.5)
    GUICtrlCreateLabel($s_Information, 8, 8, 900, 50)
    Local $id_ListView_1 = GUICtrlCreateListView("", 0, 52, 900, 600, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Local $h_ListView_Wybierz = ControlGetHandle($hGuiForm_1, "", $id_ListView_1)

    Local $id_Button_Select = GUICtrlCreateButton("&Wybierz zaznaczone", 0, 655, 900 - 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Select, 0xA6CAF0)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    Local $id_Button_Cancel = GUICtrlCreateButton("&Anuluj", 900 - 200, 655, 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Cancel, 0xFFFFE1)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW)

    #Region - FillUp ListView
    _GUICtrlListView_BeginUpdate($h_ListView_Wybierz)
    Local $a_Processing
    If $b_ArrayHasHeader Then
        $a_Processing = $a_Temp_2
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][$a])
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][0])
        EndIf
    Else
        $a_Processing = $a_Source
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
        EndIf
    EndIf

    For $id_X_Row = 0 To $i_Source_Rows_Count - 1
        _GUICtrlListView_AddItem($h_ListView_Wybierz, $a_Processing[$id_X_Row][0])
        For $id_X_Col = 0 To $i_Temp_Cols_Count - 1
            _GUICtrlListView_AddSubItem($h_ListView_Wybierz, $id_X_Row, $a_Processing[$id_X_Row][$id_X_Col], $id_X_Col)
        Next
    Next
    _GUICtrlListView_ClickItem($h_ListView_Wybierz, 1, "left", True, 2)
    Send("{CTRLDOWN}{SHIFTDOWN}")
    ControlSend($hGuiForm_1, "", $id_ListView_1, "{NUMPADADD}")
    Send("{SHIFTUP}{CTRLUP}")
    If $b_ArrayHasHeader Then _GUICtrlListView_DeleteItem($h_ListView_Wybierz, 0)
    _GUICtrlListView_EndUpdate($h_ListView_Wybierz)
    #EndRegion - FillUp ListView
    Local $iSeconds = TimerDiff($hTimer) / 1000
    ConsoleWrite("! $iSeconds = " & $iSeconds & @CRLF)

    Local $nMsg
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $id_Button_Select
                If _GUICtrlListView_GetSelectionMark($h_ListView_Wybierz) = -1 Then
                    GUIDelete($hGuiForm_1)
                    Return SetError(1, 0, "Nie dokonano wyboru")
                EndIf
                Local $a_Result = StringSplit(_GUICtrlListView_GetSelectedIndices($h_ListView_Wybierz), "|") ; Returns pipe "|" delimited string, "|")
                GUIDelete($hGuiForm_1)
                If $b_ArrayHasHeader Then
                    For $IDX_Choosen = 1 To $a_Result[0] ; zwiększam wartosc o jeden bo wyniki z listview sa mniejsze o jeden w stosunku tablicy poczatkowej
                        $a_Result[$IDX_Choosen] += 1
                    Next
                EndIf
                Return $a_Result
            Case $id_Button_Cancel, $GUI_EVENT_CLOSE
                GUIDelete($hGuiForm_1)
                Return SetError(1, 0, "Nie dokonano wyboru")
        EndSwitch
    WEnd
EndFunc   ;==>_Array_Select

On my PC it takes about 11 second to display all the data.
My goal is to use normal ListView and not VirtualListview, but I must speed up this somehow.

I think that I must to use this following tip:

  

On 3/22/2015 at 2:17 PM, LarsJ said:

If not more than 10,000 rows have to be inserted in a listview, a standard listview is sufficiently rapid. Because of speed you should use native (built-in) functions to fill the listview and not functions in GuiListView.au3 UDF. When the listview is filled, you can use all the functions in the UDF.

 

and adopt some trick from @LarsJ LvStandard.au3

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
Share on other sites
  • 2 weeks later...

As for now I have this:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

_Example(2000, 40)

Func _Example($iRows, $iCols)
    Local $a_Test[$iRows][$iCols]
    For $ROW = 0 To $iRows - 1
        For $COL = 0 To $iCols - 1
            $a_Test[$ROW][$COL] = 'Test long text here #' & $ROW & "," &  $COL
        Next
    Next

;~  Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', True)
    Local $a_Selected = _Array_Select($a_Test, 'Testing', 'Choose few rows', False)
    _ArrayDisplay($a_Selected, '$a_Selected')
EndFunc   ;==>_Example


Func _Array_Select(ByRef $a_Source, $s_title, $s_Information, $b_ArrayHasHeader = True, $hWnd_Parent = 0)
    Local $hTimer = TimerInit()
    If Not IsArray($a_Source) Then Return SetError(1, 0, "is not array")

    Local $i_Source_Rows_Count = UBound($a_Source, $UBOUND_ROWS), $i_Source_Cols_Count = UBound($a_Source, $UBOUND_COLUMNS)
    Local $i_Temp_Cols_Count
    If $i_Source_Cols_Count < 0 Then $i_Source_Cols_Count = 0
    If $i_Source_Cols_Count = 0 Then ; If 1D Array
        $i_Temp_Cols_Count = $i_Source_Cols_Count + 1
    Else
        $i_Temp_Cols_Count = $i_Source_Cols_Count
    EndIf

    Local $a_Temp_2[$i_Source_Rows_Count][$i_Temp_Cols_Count]
    If $b_ArrayHasHeader Then
        For $iCols = 0 To $i_Temp_Cols_Count - 1
            For $iRows = 0 To $i_Source_Rows_Count - 1
                If $i_Source_Cols_Count > 0 Then
                    $a_Temp_2[$iRows][$iCols] = $a_Source[$iRows][$iCols]
                Else
                    $a_Temp_2[$iRows][$iCols] = $a_Source[$iRows]
                EndIf
            Next
        Next
    EndIf

    Local $hGuiForm_1 = GUICreate($s_title, 900, 680, 100, -1, -1, -1, $hWnd_Parent)
    GUISetFont(8.5)
    GUICtrlCreateLabel($s_Information, 8, 8, 900, 50)
    Local $id_ListView_1 = GUICtrlCreateListView("", 0, 52, 900, 600, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Local $h_ListView_Wybierz = ControlGetHandle($hGuiForm_1, "", $id_ListView_1)

    Local $id_Button_Select = GUICtrlCreateButton("&Wybierz zaznaczone", 0, 655, 900 - 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Select, 0xA6CAF0)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
    Local $id_Button_Cancel = GUICtrlCreateButton("&Anuluj", 900 - 200, 655, 200, 25, 0)
    GUICtrlSetBkColor($id_Button_Cancel, 0xFFFFE1)
    GUICtrlSetResizing(-1, $GUI_DOCKBOTTOM + $GUI_DOCKSIZE)
;~  GUISetState(@SW_SHOW)

    #Region - FillUp ListView
    _GUICtrlListView_BeginUpdate($h_ListView_Wybierz)
    Local $a_Processing
    If $b_ArrayHasHeader Then
        $a_Processing = $a_Temp_2
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][$a])
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, $a_Processing[0][0])
        EndIf
    Else
        $a_Processing = $a_Source
        If $i_Source_Cols_Count > 0 Then
            For $a = 0 To $i_Temp_Cols_Count - 1
                _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
            Next
        Else
            _GUICtrlListView_AddColumn($h_ListView_Wybierz, '')
        EndIf
    EndIf

;~  For $id_X_Row = 0 To $i_Source_Rows_Count - 1
;~      _GUICtrlListView_AddItem($h_ListView_Wybierz, $a_Processing[$id_X_Row][0])
;~      For $id_X_Col = 0 To $i_Temp_Cols_Count - 1
;~          _GUICtrlListView_AddSubItem($h_ListView_Wybierz, $id_X_Row, $a_Processing[$id_X_Row][$id_X_Col], $id_X_Col)
;~      Next
;~  Next
    FillListView($id_ListView_1, $a_Source, UBound($a_Source, 1))

    _GUICtrlListView_ClickItem($h_ListView_Wybierz, 1, "left", True, 2)
    Send("{CTRLDOWN}{SHIFTDOWN}")
    ControlSend($hGuiForm_1, "", $id_ListView_1, "{NUMPADADD}")
    Send("{SHIFTUP}{CTRLUP}")
    If $b_ArrayHasHeader Then _GUICtrlListView_DeleteItem($h_ListView_Wybierz, 0)
    _GUICtrlListView_EndUpdate($h_ListView_Wybierz)
    #EndRegion - FillUp ListView
    GUISetState(@SW_SHOW)
    Local $iSeconds = TimerDiff($hTimer) / 1000
    ConsoleWrite("! $iSeconds = " & $iSeconds & @CRLF)

    Local $nMsg
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $id_Button_Select
                If _GUICtrlListView_GetSelectionMark($h_ListView_Wybierz) = -1 Then
                    GUIDelete($hGuiForm_1)
                    Return SetError(1, 0, "Nie dokonano wyboru")
                EndIf
                Local $a_Result = StringSplit(_GUICtrlListView_GetSelectedIndices($h_ListView_Wybierz), "|") ; Returns pipe "|" delimited string, "|")
                GUIDelete($hGuiForm_1)
                If $b_ArrayHasHeader Then
                    For $IDX_Choosen = 1 To $a_Result[0] ; zwiększam wartosc o jeden bo wyniki z listview sa mniejsze o jeden w stosunku tablicy poczatkowej
                        $a_Result[$IDX_Choosen] += 1
                    Next
                EndIf
                Return $a_Result
            Case $id_Button_Cancel, $GUI_EVENT_CLOSE
                GUIDelete($hGuiForm_1)
                Return SetError(1, 0, "Nie dokonano wyboru")
        EndSwitch
    WEnd
EndFunc   ;==>_Array_Select

Func FillListView($idLV, ByRef $aItems, $iRows)
    Local $tLVITEM = DllStructCreate($tagLVITEM)
    Local $pLVITEM = DllStructGetPtr($tLVITEM), $k, $s
    DllStructSetData($tLVITEM, "Mask", $LVIF_IMAGE)   ; Icon (or image)
    DllStructSetData($tLVITEM, "SubItem", 0)          ; First column
    For $j = 0 To $iRows - 1
        ; Text
        $s = $aItems[$k + $j][0]
        For $l = 1 To UBound($aItems, 2) - 1
            $s &= "|" & $aItems[$k + $j][$l]
        Next
        GUICtrlCreateListViewItem($s, $idLV)              ; Add item and all texts
    Next
EndFunc   ;==>FillListView

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * for other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-10-18

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
    • By vinnyMS
      #Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0]) $w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns  
       
      i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel
      you will have to create a "copy" button if possible
      array.au3 2.txt
    • By DannyJ
      I have a dataset like this, (a strubg)
      Username: User1 Type: Admin RegDate: 1999 Username: User2 Type: User RegDate: 2000 How to make a 2 dimensional array that I can display with _ArrayDisplay?
      This would be a perfect 2D array to represent my data:
      Username           Tpye RegDate User1              Admin 1999 User2              User 2000   If you run this Powershell this powershell command, you can get this dataset that I am talking about:
      Get-LocalUser | Select * With this code you can try it to read into a string:
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion $sCommand = "powershell.exe Get-LocalUser | Select *" Local $iPid = Run($sCommand, @WorkingDir , @SW_SHOW , $STDOUT_CHILD) ProcessWaitClose($iPid) Local $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) How can I correctly split $sOutput into a 2D array (with the above mentioned layout) that I can display and I work with?
    • By kovlad
      My solution is to write nested arrays without copying.
      The problem was described hier.
       
      Function:
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayNestedSet ; Description ...: Assigns a value to an element of a nested 1D array. ; Syntax ........: _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue) ; Parameters ....: $aArray - an array of arrays. ; $vIndex - an index or 1d-array of indexes; ; a size if $vValue not defined (zero to delete). ; $vValue - a value (create, resize or delete if not defined). ; ; Return values .: on success - 1 ; @extended - nesting level of operation ; on failure - 0 ; @extended - nesting level of error ; @error = 1 - invalid array ; @error = 2 - invalid index ; Author ........: ; Modified ......: kovlad ; Remarks .......: ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/185638-assign-a-value-to-an-array-in-array-element/ ; https://www.autoitscript.com/trac/autoit/ticket/3515?replyto=description ; Example .......: Yes ; =============================================================================================================================== Func _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue = Default) Local $extended = @extended + 1 If IsArray($vIndex) Then If UBound($vIndex, 0) <> 1 Then _ Return SetError(2, $extended) If UBound($vIndex) > 1 Then If UBound($aArray, 0) <> 1 Then _ Return SetError(1, $extended) ; keep index for this array Local $i = $vIndex[0] If $i < 0 Or UBound($aArray) <= $i Then _ Return SetError(2, $extended) ; delete index of this array _ArrayDelete($vIndex, 0) ; recursive function call Local $return = _ArrayNestedSet($aArray[$i], $vIndex, $vValue) If @error Then Return SetError(@error, @extended + 1, 0) Else Return SetExtended(@extended + 1, 1) EndIf Else $vIndex = $vIndex[0] EndIf EndIf If $vValue = Default Then If $vIndex < 0 Then _ Return SetError(2, $extended) If $vIndex = 0 Then ; delete array and free memory $aArray = 0 Return SetExtended($extended, 1) EndIf If UBound($aArray, 0) = 1 Then ; resize array keeping data ReDim $aArray[$vIndex] Return SetExtended($extended, 1) Else ; create new nested array Local $aTmp[$vIndex] $aArray = $aTmp Return SetExtended($extended, 1) EndIf Else If UBound($aArray) <= $vIndex Then _ Return SetError(2, $extended + 1) ; set value of array entry $aArray[$vIndex] = $vValue Return SetExtended($extended, 1) EndIf EndFunc  
      Examples:
      ; write value to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 1st nested array" & @CRLF) Local $aTmp1[4] = [1,2,3,4] _ArrayDisplay($aTmp1, "$aTmp1") Local $aArray[2] = [$aTmp1] ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 3, 14) = " & _ArrayNestedSet($aArray[0], 3, 14) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; resize 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 1st nested array" & @CRLF) ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 8) = " & _ArrayNestedSet($aArray[0], 8) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; write array to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write array to 1st nested array" & @CRLF) Local $aTmp11[4] = [11,12,13,14] _ArrayDisplay($aTmp11, "$aTmp11") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 2, $aTmp11) = " & _ArrayNestedSet($aArray[0], 2, $aTmp11) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; write value to 2nd nested array using index array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 2nd nested array using index array" & @CRLF) Local $aIndex1[2] = [2,3] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1, 140) = " & _ArrayNestedSet($aArray[0], $aIndex1, 140) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; resize 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 2nd nested array" & @CRLF) Local $aIndex1[2] = [2,8] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1) = " & _ArrayNestedSet($aArray[0], $aIndex1) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; create new 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : create new 3rd nested array" & @CRLF) Local $aIndex2[3] = [2,7,6] _ArrayDisplay($aIndex2, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex2) = " & _ArrayNestedSet($aArray[0], $aIndex2) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay((($aArray[0])[2])[7], ")($aArray[0])[2])[7]") ; delete 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 3rd nested array" & @CRLF) Local $aIndex3[3] = [2,7,0] _ArrayDisplay($aIndex3, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex3) = " & _ArrayNestedSet($aArray[0], $aIndex3) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray((($aArray[0])[2])[7]) = " & IsArray((($aArray[0])[2])[7]) & @CRLF & @CRLF) ; write 0 in 1st nested array to delete the 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write 0 in 1st nested array to delete the 2nd nested array" & @CRLF) Local $aIndex4[1] = [2] _ArrayDisplay($aIndex4, "$aIndex4") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex4, 0) = " & _ArrayNestedSet($aArray[0], $aIndex4, 0) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray(($aArray[0])[2]) = " & IsArray(($aArray[0])[2]) & @CRLF & @CRLF) ; delete 1st nested array (same as '$aArray[0] = 0') ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 1st nested array (same as '$aArray[0] = 0')" & @CRLF) Local $aIndex5[1] = [0] _ArrayDisplay($aIndex5, "$aIndex5") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex5) = " & _ArrayNestedSet($aArray[0], $aIndex5) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray($aArray[0]) = " & IsArray($aArray[0]) & @CRLF & @CRLF)  
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
×
×
  • Create New...