zwierzak Posted September 18, 2010 Share Posted September 18, 2010 (edited) Hello. I have a problem. I've described it in the code's comments expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $item[30] GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("X|Y", 10, 10, 165, 200) $button = GUICtrlCreateButton("Refresh", 5, 220, 70, 20) $button2 = GUICtrlCreateButton("test", 75, 220, 70, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $button $var = WinList("notepad") For $i = 1 To $var[0][0] If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then $string = StringSplit($var[$i][0], "-") $item[$i] = GUICtrlCreateListViewItem($string[3], $listview) ;HOW TO MAKE IT LIKE THIS? ;$string[$i] = StringSplit($var[$i][0], "-") ;$item[$i] = GUICtrlCreateListViewItem($string[$i][3], $listview) ;I want to make X number of strings, but it already has got 1 array. How to make another one - add new dimension to the existing array? EndIf Next Case $button2 MsgBox(0,GUICtrlRead($listview), "text") EndSwitch WEnd Func IsVisible($handle) If BitAND(WinGetState($handle), 1) Then Return 1 Else Return 0 EndIf EndFunc ;==>IsVisible I'd like to make it like this but dunno how ;HOW TO MAKE IT LIKE THIS? ;$string[$i] = StringSplit($var[$i][0], "-") ;$item[$i] = GUICtrlCreateListViewItem($string[$i][3], $listview) ;I want to make X number of strings, but it already has got 1 array. How to make another one - add new dimension to the existing array? Edited September 18, 2010 by zwierzak Link to comment Share on other sites More sharing options...
MvGulik Posted September 18, 2010 Share Posted September 18, 2010 (edited) "How to add new dimension to the existing array?" Assuming: while maintaining the data inside the array. By copying the data from one array(old) to the other array(new) Redim allows you to change the size of the exiting dimensions while maintaining the data inside the array. (Redim also allows the number of dimensions of a existing array to be changed, but in such a case the array data will be lost/cleared.) Edited September 18, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 18, 2010 Moderators Share Posted September 18, 2010 zwierzak,Just use ReDim like this: #include <Array.au3> Global $aArray[2][2] = [["A", "B"], ["C", "D"]] _ArrayDisplay($aArray) ReDim $aArray[UBound($aArray)][3] _ArrayDisplay($aArray)M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ProgAndy Posted September 18, 2010 Share Posted September 18, 2010 (edited) @Melba23: As far as I remember this wasn't possible in older versions of AutoIt, but it seems the behaviour has changed. This means, MvGulik's statment is now incorrect. Edited September 18, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
zwierzak Posted September 18, 2010 Author Share Posted September 18, 2010 Thats weird for me, cos Redim didn't work for me. So I've tried to make another array which will keep the previous array's data. And u know what? It works xD Global $newstring[30] $string = StringSplit($var[$i][0], "-") _ArrayDisplay($string) $newstring[$i] = $string[3] $item[$i] = GUICtrlCreateListViewItem($newstring[$i], $listview) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 18, 2010 Moderators Share Posted September 18, 2010 (edited) Guys,Do not get confused between the number of dimensions (the number of [ ] after the array name) and the size of existing dimensions (changing the number within an existing [ ]). If you want to retain the existing data in an array, there is no way to increase the number of dimensions, you have to copy the data from the existing array to another array with the required number of dimensions. Using any form of declaration (Global/Local/Dim/Redim) and changing the number of dimensions will erase all existing elements from the array.However, by using ReDim you can alter the size of existing dimensions without deleting existing elements as I showed above. M23Edit: Amended as explained in the posts below. Edited September 19, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ProgAndy Posted September 18, 2010 Share Posted September 18, 2010 Oh right. I really should read more carefully. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
RagsRevenge Posted September 18, 2010 Share Posted September 18, 2010 Guys, ReDim will not increase the number of dimensions - it will not turn $aArray[x][y] into $aArray[x][y][z]. But it will alter the size of existing dimensions as I showed above. Do not get confused between the number of dimensions (the number of [ ] after the array name) and the size of existing dimensions (changing the number within an existing [ ]). M23 Oh dear, I've written a function specially to deal with my misreading of that. D Link to comment Share on other sites More sharing options...
MvGulik Posted September 18, 2010 Share Posted September 18, 2010 ReDim will not increase the number of dimensions - it will not turn $aArray[x][y] into $aArray[x][y][z]. But it will alter the size of existing dimensions as I showed above. Brrr. Why do I have a problem with this. O yea, being a nitpick. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2010 Moderators Share Posted September 19, 2010 MvGulik,What is bugging you about the statement? I am happy to change it if you feel it is less than clear. My definition of the number of dimensions matches that used in geometry:1D array = a line of elements, with a single coordinate2D array = a plane with x,y coordinates3D array = a volume with x, y, z coordinates......The size of the dimensions just sets the length, area and volume respectively of the space needed to hold the elements. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Ascend4nt Posted September 19, 2010 Share Posted September 19, 2010 Just taking a shot in the dark here Melba, but I'm guessing the nitpicking is about the fact that you can increase the number of dimensions with ReDim. The problem is doing that will destroy the data and has a net effect of being just another new 'Dim'.MvGulik was correct in his first post regarding copying the data to a new multi-dimensional array, as that is the only way to 'add' dimensions. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
MvGulik Posted September 19, 2010 Share Posted September 19, 2010 (edited) Nothing wrong with your definitions. You know them better than I do. But... Local $array[1]=[1] DebugOut('$array', $array) ;### Debug DebugOut. ReDim $array[1][2] DebugOut('$array', $array) ;### Debug DebugOut.!> MAIN() --- --- 0 (array dump), $array:[1]. . 000 |I3| 1 (0x00.00.00.00.00.00.00.01) --- --- 0 [0,0] --- --- 0 (array dump), , $array:[1][2]. --- |--| 0| 1| [0] |St| | | --- --- 0 [0,0] !< MAIN() Redim just changed the number of dimensions. from array[x] to array[x][y] (its the fact that you can't do it while preserving the data inside a array.) --- Depending on the point of view. Your also correct of course. As it could be argued that when Redim is used to change the number of dimensions on a existing array. Redim will internally toss the existing array/data and create a new(empty) array for the used variable/$name. Edited September 19, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2010 Moderators Share Posted September 19, 2010 MvGulik & Ascend4nt,Understood. I must admit that I had not realised that ReDim could actually redeclare an array with a different number of dimensions - albeit loosing the data in the process. I have only ever used it to resize existing dimensions - as the OP needed.You live and learn each day - I have amended the earlier post. Thanks for pointing it out. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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