Jump to content

How to compare values of an array?


Recommended Posts

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 "".

Link to comment
Share on other sites

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 "".

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...