Fossil Rock Posted September 28, 2006 Share Posted September 28, 2006 I can't seem to get my thinking around how to filter an array. What I would like to do is filter out unique values for a listview based on any one of the subitems. An example would be to have 100 items and 15 of them are unique. I need to filter down to just the 15 and put that in a listbox/combobox. The listview will only be used to verify it's working correctly. Any suggestions or code scraps ... anything to get me going in the right direction. Thanks Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 28, 2006 Share Posted September 28, 2006 Hi, I would create a second array, write 1 entry then get second value check against the new array. If match do nothing else add to new array. So long, Mega PS: Just a quick idea Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
GaryFrost Posted September 28, 2006 Share Posted September 28, 2006 might want to look at http://www.autoitscript.com/forum/index.ph...ost&p=55608 for the unique array SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Fossil Rock Posted September 28, 2006 Author Share Posted September 28, 2006 Thanks, that looks like it will do the trick. Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
Fossil Rock Posted September 28, 2006 Author Share Posted September 28, 2006 How would I make this code return a list of unique values for say $results[0][3] so that it could be put in a listview or listbox ? #include<Array.au3> Const $title = "My Documents" Const $CID = 0x00000001 Send("#r") WinWaitActive("Run") Sleep(500) Send($title) Sleep(500) Send("{Enter}") WinWaitActive($title) Sleep(500) $RowCount = ControlListView ($title,"", $CID, "GetItemCount") $ColCount = ControlListView ($title,"", $CID, "GetSubItemCount") Dim $results[$RowCount][$ColCount] For $row = 0 to $RowCount - 1 For $col = 0 to $ColCount - 1 $results[$row][$col] = ControlListView($title,"", $CID,"GetText", $row, $col) Next Next _ArrayUnique($results) Func _ArrayUnique(ByRef $results, $vDelim = '', $iBase = 1, $iUnique = 1) If $vDelim = '' Then $vDelim = Chr(01) Local $sHold For $iCC = $iBase To UBound($results) - 1 If Not StringInStr($vDelim & $sHold & $vDelim, $results[$iCC] & $vDelim, $iUnique) Then _ $sHold &= $results[$iCC] & $vDelim Next Return StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim) EndFunc Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 28, 2006 Share Posted September 28, 2006 (edited) How would I make this code return a list of unique values for say $results[0][3] so that it could be put in a listview or listbox ? #include<Array.au3> Const $title = "My Documents" Const $CID = 0x00000001 Send("#r") WinWaitActive("Run") Sleep(500) Send($title) Sleep(500) Send("{Enter}") WinWaitActive($title) Sleep(500) $RowCount = ControlListView ($title,"", $CID, "GetItemCount") $ColCount = ControlListView ($title,"", $CID, "GetSubItemCount") Dim $results[$RowCount][$ColCount] For $row = 0 to $RowCount - 1 For $col = 0 to $ColCount - 1 $results[$row][$col] = ControlListView($title,"", $CID,"GetText", $row, $col) Next Next _ArrayUnique($results) Func _ArrayUnique(ByRef $results, $vDelim = '', $iBase = 1, $iUnique = 1) If $vDelim = '' Then $vDelim = Chr(01) Local $sHold For $iCC = $iBase To UBound($results) - 1 If Not StringInStr($vDelim & $sHold & $vDelim, $results[$iCC] & $vDelim, $iUnique) Then _ $sHold &= $results[$iCC] & $vDelim Next Return StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim) EndFunc First things first... Your $results array for input is a 2D array and the previous conversations were all about 1D arrays, I believe (from your first post): An example would be to have 100 items and 15 of them are unique. Second things second... Don't use the same name for the internal ByRef variable inside your function. I'm still digesting what you were trying to do for the third thing... Update: More digesting of your code is just giving me gas... The SysListView321 that you are reading is the explorer view of the My Documents folder. The extra colums are just size, date/time, etc., and only the first column has the file names. What kind of unique entries are you filtering for? Each unique file size? Unique date/time stamps? I don't get it... Edited September 28, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Fossil Rock Posted September 28, 2006 Author Share Posted September 28, 2006 (edited) First things first... Your $results array for input is a 2D array and the previous conversations were all about 1D arrays, I believe (from your first post):What I would like to do is filter out unique values for a listview based on any one of the subitems.Sorry if I wasn't clear on wanting the subitems filtered. I was under the impression "Items" referred to single dimension (or the first of a multi) and "Subitems" referred to a multi-dimensional. My bad ... Second things second... Don't use the same name for the internal ByRef variable inside your function.I'm trying to learn and some of this stuff doesn't sink in until I see a good example, other stuff comes pretty easy to me.I'm still digesting what you were trying to do for the third thing... I used that as an example, it can be any listview. Using the 'My Documents' example, I would like the 'Type' column filtered for unique items... say there are 20 folders and 10 .doc files and 5 .pdf files and 25 .txt files totaling 60 items. Filtered for uniqueness should return 4 items (Folder, .doc, .pdf, .txt). Ultimately I would like to put those items in a listbox or listview... whatever works... then choose one of the 4 to refresh the list and filter another column.EDIT: Update: More digesting of your code is just giving me gas... The function part is SmOke_N's and the array part I created from seeing an example somewhere. Not truely 'my code'. Edited September 28, 2006 by Fossil Rock Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
Uten Posted September 28, 2006 Share Posted September 28, 2006 I think you want something like an associative array (It's called so in awk, In perl it's a hash and in VB/C#(?) a collection). Unfortunately AutoIt does not come with this out of the box. But there are some UDF's lying around. I also think I have seen a plugin. Happy hunting in scripts & scraps. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 28, 2006 Share Posted September 28, 2006 EDIT: The function part is SmOke_N's and the array part I created from seeing an example somewhere. Not truely 'my code'. See, SmOke'd foods give me gas! Anyway, this tested well. Note 2D array modifications: expandcollapse popup#include<Array.au3> Const $title = "My Documents" Const $CID = 0x00000001 Send("#r") WinWaitActive("Run") Sleep(500) Send($title) Sleep(500) Send("{Enter}") WinWaitActive($title) Sleep(500) $RowCount = ControlListView($title, "", $CID, "GetItemCount") $ColCount = ControlListView($title, "", $CID, "GetSubItemCount") Dim $aListView[$RowCount][$ColCount] For $row = 0 To $RowCount - 1 For $col = 0 To $ColCount - 1 $aListView[$row][$col] = ControlListView($title, "", $CID, "GetText", $row, $col) Next Next $ColOfInterest = 2 ; Col number of Type field $aResults = _ArrayUnique2D($aListView, $ColOfInterest) If Not @error Then _ArrayDisplay($aResults, "Results, Col: " & $ColOfInterest) Else MsgBox(16, "Error", "_ArrayUnique2D() returned @error = " & @error) EndIf ; ========================================================================= ; Function _ArrayUnique2D() ; Return 1D array of unique items from selected column in 2D array. ; Call with _ArrayUnique2D($aInput [, $ColNum]) where: ; $aInput = 2D array to search ; $ColNum (optional) = 0-based column to search on ; Returns a 1D array of unique values with [0] = count ; On failure, returns non-zero @error ; ========================================================================= Func _ArrayUnique2D($aInput, $ColNum = 0) If Not IsArray($aInput) Then Return SetError(1, 0, "") ; Input is not an array If UBound($aInput, 0) <> 2 Then Return SetError(2, 0, "") ; Input is not 2D array If $ColNum > UBound($aInput, 2) - 1 Then Return SetError(3, 0, "") ; Search column is too high Local $aReturn[1], $i, $r For $i = 0 To UBound($aInput) - 1 For $r = 0 To UBound($aReturn) - 1 If $aInput[$i][$ColNum] = $aReturn[$r] Then ContinueLoop 2 Next _ArrayAdd($aReturn, $aInput[$i][$ColNum]) Next $aReturn[0] = UBound($aReturn) - 1 Return $aReturn EndFunc ;==>_ArrayUnique2D Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Fossil Rock Posted September 28, 2006 Author Share Posted September 28, 2006 My gift to your sir ..... http://www.autoitscript.com/fileman/users/Fossil%20Rock/AU3Penguin.png Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 29, 2006 Share Posted September 29, 2006 My gift to your sir ..... http://www.autoitscript.com/fileman/users/Fossil%20Rock/AU3Penguin.pngOhh! He's so CUTE! I think I'll name him Jon. Jon De Tux, or JdeT for short... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Fossil Rock Posted September 29, 2006 Author Share Posted September 29, 2006 Thank for helping me learn something new... Agreement is not necessary - thinking for one's self is! Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 29, 2006 Share Posted September 29, 2006 Thank for helping me learn something new... You're welcome. I've learned a lot of usefull stuff by working on someone else's problem on the forum, so I get quite a bit out of it too. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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