momo1984 Posted August 20, 2012 Share Posted August 20, 2012 Hi, let`s say we have an array like : Local $array[5]= ["1","2","2","3","1"] and I need to display how many times each element occured in the array like : 1 --> 2 times 2 --> 2 times 3 --> 1 time How can I do this ? Thank you Link to comment Share on other sites More sharing options...
Andreik Posted August 20, 2012 Share Posted August 20, 2012 Use _ArrayFindAll() function. Check out helpfile for parameters. Link to comment Share on other sites More sharing options...
Spiff59 Posted August 20, 2012 Share Posted August 20, 2012 If you have a large list, you'll find the _Array UDF functions painfully slow. You could play around with something liek this: Local $array[14]= [1, 3, 1, 0, 1, "0","2","2","3", 0, "1", "", "Arf!", "Arf!"] For $x = 0 to UBound($array) - 1 ; count 'em up $y = "__" & $array[$x] If IsString($array[$x]) Then $y &= "_s" If IsDeclared($y) Then Assign($y, Eval($y) + 1) $array[$x] = Chr(0) Else Assign($y, 1) EndIf Next For $x = 0 to UBound($array) - 1 ; display results If $array[$x] == Chr(0) Then ContinueLoop If IsString($array[$x]) Then $suffix = "_s" $desc = "str" Else $suffix = "" $desc = "num" EndIf ConsoleWrite("Value: " & $array[$x] & " (" & $desc & ") first found in element: " & $x & " occurs: " & Eval("__" & $array[$x] & $suffix) & @CRLF) Next You could almost cut that code in half if you didn't care about distinguishing between 1 and "1", or 0 and "0" and "". momo1984 1 Link to comment Share on other sites More sharing options...
momo1984 Posted August 20, 2012 Author Share Posted August 20, 2012 If you have a large list, you'll find the _Array UDF functions painfully slow.You could play around with something liek this:Local $array[14]= [1, 3, 1, 0, 1, "0","2","2","3", 0, "1", "", "Arf!", "Arf!"] For $x = 0 to UBound($array) - 1 ; count 'em up $y = "__" & $array[$x] If IsString($array[$x]) Then $y &= "_s" If IsDeclared($y) Then Assign($y, Eval($y) + 1) $array[$x] = Chr(0) Else Assign($y, 1) EndIf Next For $x = 0 to UBound($array) - 1 ; display results If $array[$x] == Chr(0) Then ContinueLoop If IsString($array[$x]) Then $suffix = "_s" $desc = "str" Else $suffix = "" $desc = "num" EndIf ConsoleWrite("Value: " & $array[$x] & " (" & $desc & ") first found in element: " & $x & " occurs: " & Eval("__" & $array[$x] & $suffix) & @CRLF) NextYou could almost cut that code in half if you didn't care about distinguishing between 1 and "1", or 0 and "0" and "".Thank you so much, it worked after pasting it.I will look into the code and try to understand it all in all and hope if I get stuck that you may help me in the future :-)Thanks again 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