littlebigman Posted yesterday at 01:18 PM Posted yesterday at 01:18 PM Hello, This is my first try at using 2D arrays with the Array.au3 UDF, and Googling + wiki didn't help. How do I add a new row? _ArrayDisplay() is always empty. #include <Array.au3> Local $arr[0][0] ;_ArrayAdd($arr, [["My URL", "My title"]]) ;_ArrayAdd($arr, ["My URL", "My title"]) ;_ArrayAdd($arr, "My URL" & "|" & "My title") Local $new = StringFormat("%s#%s", "My URL", "My title") _ArrayAdd($arr, $new,0,"#") _ArrayDisplay($arr, "Collected Chrome URLs") Thank you.
argumentum Posted yesterday at 02:07 PM Posted yesterday at 02:07 PM (edited) so, ["My URL", "My title"]] is what you want to have 🤔 #include <Array.au3> Local $arr[1][2] ; <<<<< change that ;_ArrayAdd($arr, [["My URL", "My title"]]) ;_ArrayAdd($arr, ["My URL", "My title"]) ;_ArrayAdd($arr, "My URL" & "|" & "My title") Local $new = StringFormat("%s#%s", "My URL", "My title") _ArrayAdd($arr, $new,0,"#") _ArrayDisplay($arr, "Collected Chrome URLs") Edit: use #AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 as the 1st line of every script will help you to code better code. Edited yesterday at 02:09 PM by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting
littlebigman Posted yesterday at 02:14 PM Author Posted yesterday at 02:14 PM (edited) Thanks. I was about to reply. I naïvely assumed _ArrayAdd() auto-redimensioned an array to fit a new row, but it looks like it must be done manually: Local $arr[0][0] ReDim $arr[0][2] ;BAD ;_ArrayAdd($arr, [["My URL" , "My title"]]) ;BAD _ArrayAdd($arr, ["My URL" , "My title"]) ;_ArrayAdd($arr, "My URL" & "|" & "My title") _ArrayDisplay($arr, "Collected Chrome URLs") Edit: While True … ;add one row ReDim $arr[UBound($arr, $UBOUND_ROWS)][2] Local $new = StringFormat("%s#%s", $sCurrentURL, $sTitle) _ArrayAdd($arr, $new,0,"#") WEnd _ArrayDisplay($arr, "Collected Chrome URLs") Edited yesterday at 02:29 PM by littlebigman argumentum 1
water Posted yesterday at 02:53 PM Posted yesterday at 02:53 PM It is always a good idea to check the error code after calling a function: #include <Array.au3> ; Working code Local $arr1[0][2] _ArrayAdd($arr1, "My URL" & "|" & "My title") MsgBox(0, "Example 1 - Error code", @error) _ArrayDisplay($arr1, "Collected Chrome URLs") ; Code returns an error Local $arr2[0][1] _ArrayAdd($arr2, "My URL" & "|" & "My title") MsgBox(0, "Example 2 - Error code", @error) _ArrayDisplay($arr2, "Collected Chrome URLs") My understanding is that _ArrayAdd only adds rows to an existing array but the number of columns has to be >= the number of elements of the string to be added. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
littlebigman Posted yesterday at 05:39 PM Author Posted yesterday at 05:39 PM (edited) Indeed: #cs 1 - $aArray is not an array 2 - $aArray is not a 1 or 2 dimensional array 3 - $vValue has too many columns to fit into $aArray 4 - $iStart outside array bounds (2D only) 5 - Number of dimensions for $avArray and $vValue arrays do not match #CE I'll read up on _ArrayAdd() to understand what this means: Quote 2D arrays: $sDelim_Item delimited string - adds 1 row, columns filled if enough items $sDelim_Row delimited string - adds as many rows as items, only 1 column filled $sDelim_Item & Row delimited string - adds rows and items, depending on split points 0-based 2D array - adds as many rows/columns as in array Edited yesterday at 05:39 PM by littlebigman argumentum 1
water Posted yesterday at 05:42 PM Posted yesterday at 05:42 PM Run the example scripts which you can find in the helpfile for _ArrayAdd My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Solution littlebigman Posted yesterday at 06:27 PM Author Solution Posted yesterday at 06:27 PM (edited) Yup Turns out _ArrayAdd() takes care of adding rows, but the number of columns has to be correct or I get error 3 "$vValue has too many columns to fit into $aArray": Local $arr[0][2] _ArrayAdd($arr, "item1|item2") _ArrayAdd($arr, "item1|item2") _ArrayAdd($arr, "item1|item2") Edited 10 hours ago by littlebigman
water Posted 23 hours ago Posted 23 hours ago Do all rows have the same number of items? Or is there a need to redim the array before adding new rows? How many rows do you need to add to the array? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
littlebigman Posted 22 hours ago Author Posted 22 hours ago They'll all have the same number of items. I'll need to add no more than a few ten's of rows. It's just that it's my first time using a listview. I'll keep reading and experimenting. https://www.autoitscript.com/wiki/Arrays#Changing_Array_Sizes_With_ReDim https://www.autoitscript.com/autoit3/docs/libfunctions/_ArrayAdd.htm https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateListView.htm
littlebigman Posted 6 hours ago Author Posted 6 hours ago Still learning… In the help file, I went through the "GUICtrl*()" and "_GuiCtrlListView_*()" sections, but didn't find how to get the headers in a listview to actually look like headers, ie. grey background. Is it normal, or do I need to user other parameters? $Form1 = GUICreate("", 615, 430, 267, 124) $ListView1 = GUICtrlCreateListView("URL|Title", 8, 152, 594, 230, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT)) Local $aFill[][] = [["New Item 2 - 1", "New Item 2 - 2"], ["New Item 3 - 1", "https://www.acme.com/******************************************************************************************"]] _GUICtrlListView_AddArray($ListView1, $aFill) _GUICtrlListView_SetColumnWidth($ListView1, 1, $LVSCW_AUTOSIZE) GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
water Posted 5 hours ago Posted 5 hours ago (edited) I have never spent much time to color the ListView headers, but ... The following thread describes a solution: Change the 0x values to your liking or even better use the color variables you can find in ColorConstants.au3 Edited 5 hours ago by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now