dm83737 Posted July 1, 2009 Share Posted July 1, 2009 I am trying to assign the results of the _ArrayUnique function to a series of variables, but for some reason I am at a total brain freeze as how I can do so. I have searched thru the forums for something that relates to this subject and could not find any that really did what I need; they mostly dealt with files and deleting duplicates. #include <Array.au3> Local $aArray[20] = [0,0,0,1,1,1,1,1,2,2,2,2,2,2,3,3,4,4,4,5] _ArrayDisplay($aArray) $uArray = _ArrayUnique($aArray) _ArrayDisplay($uArray) ; Now what? I am stuck in a For $o = 1 To UBound($uArray) rut in that I can not come up with a way to cycle the variable name with each iteration. I also became so desperate that I tried copying the _ArrayUnique function to a new script and editing it to show the index # from the originating array in the second column and soon found that I was in WAY over my head. If there is a variation of the _ArrayUnique function out there that would have a 2nd column with the index # from the originating array, please point me in the right direction as I have not been able to dig this up on my own. Thanks for your help, Link to comment Share on other sites More sharing options...
weaponx Posted July 1, 2009 Share Posted July 1, 2009 Why would you need anything from the originating array? Do you just want to dump the contents of the new array? For $X = Ubound($aArray)-1 ConsoleWrite($aArray[$X] & @CRLF) Next Link to comment Share on other sites More sharing options...
Spiff59 Posted July 1, 2009 Share Posted July 1, 2009 Lots of ways to go about it... Can we infer from your sample array that the input will be sorted numeric values? Between a certain range? Or, might your input array have an unsorted mix of characters, numbers, strings, etc? Link to comment Share on other sites More sharing options...
dm83737 Posted July 2, 2009 Author Share Posted July 2, 2009 (edited) Why would you need anything from the originating array? Do you just want to dump the contents of the new array? For $X = Ubound($aArray)-1 ConsoleWrite($aArray[$X] & @CRLF) Next Lots of ways to go about it... Can we infer from your sample array that the input will be sorted numeric values? Between a certain range? Or, might your input array have an unsorted mix of characters, numbers, strings, etc? I guess I could have been more clear about this to start with; I am reading these values in to an array from an Excel spreadsheet, creating the new array with the ArrayUnique function, but then using those as the variables for an ArraySearch on the original array in order to alter those ranges in Excel. For example: I have a statement with 2 associate numbers (we'll use AA0000111 & BB0000222), and those associates are each under a separate company with there own codes (CCAA00111 for associate AA0000111; DDBB00222 for associate BB0000222). The resulting array from reading this column from Excel would produce something like so: Local $aArray[10] = [AA0000111,AA0000111,AA0000111BB0000222,BB0000222,CCAA00111,CCAA00111,CCAA00111,DDBB00222,DDBB002 22] Now I could set this up to ArraySearch this and be just fine with the one set variables ($a=$aArray[0], $b=$aArray[3],$c=$aArray[5],$d=$aArray[8]). The problem comes from when it reads the next Excel statement, it may look like this: Local $aArray[7] = [AA0000111,AA0000111,BB0000222,CCAA00111,CCAA00111,CCAA00111] This is where I get lost in trying to figure out a loop that will properly use the ArrayUnique entries as the basis of doing an ArraySearch on the original array so I can alter the cells in the Excel spreadsheet. I am attaching a pic of what I would like my final result to be so you can understand the goal here (as I tend to not explain things very clearly sometimes). I am adding border lines and color with ExcelCOM_UDF.au3 according to the index numbers that would be returned. Let me know if you need any more information please, thanks. Edited July 2, 2009 by dm83737 Link to comment Share on other sites More sharing options...
weaponx Posted July 2, 2009 Share Posted July 2, 2009 Stop thinking about assigning variables! You already have everything in an array. If you need to know the original cell locations you will need to use a 2-dimensional array which probably won't work with _ArrayUnique. I still can't figure out what your goal is with this information, its very cryptic. Link to comment Share on other sites More sharing options...
dm83737 Posted July 3, 2009 Author Share Posted July 3, 2009 Stop thinking about assigning variables! You already have everything in an array. If you need to know the original cell locations you will need to use a 2-dimensional array which probably won't work with _ArrayUnique. I still can't figure out what your goal is with this information, its very cryptic. weaponx, The jist of my request is this: 1) I create an array from the first column of an Excel file 2) I read out the unique values from the first array to a second array 3) I would like to then get the index numbers that _ArrayUnique found those unique values at as points to alter the Excel file (i.e. - the screen shots from my second post) My current method is very clunky and seems to have hit a snag when I go from 3 variables to 4: If $aArray[1] <> "" Then For $i = 0 to UBound($aArray-1) If $aArray[$i] = '' Then ReDim $aArray[$i] ExitLoop Endif Next Local $iEnd = $i + 1 Local $g = _ArraySearch($aArray, "EN", 0, 0, 0, 1) Local $iEN1 = $g + 2 Local $sEN1 = $aArray[$g] Local $sAG1 = $aArray[1] For $j = 0 to UBound($aArray-1) If $aArray[$j] <> $sAG1 Then ExitLoop Endif Next Local $iAG2 = $j+2 This is obviously NOT the best way to accomplish what I am asking, which is why I was placing some hope in a variation of the _ArrayUnique script being out there somewhere. I hope you understand what my goal is this time around as I do not think I can explain this in any simpler way. Any help would very much be appreciated. 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