Forgot password?

Create an account!

Forum

« back

RhinoScript – array_search

Messages

Please log in to write a message.

  • 3. atac (Dec 07, 2010 18.11):

    Hello Hanno!

    Again, you fixed my problem. Thank you very much!

    Regards,

    atac

  • 2. Hanno (Dec 07, 2010 09.40):

    Hi atac,

    I guess this is a tolerance issue. When comparing floating point values it is always a good idea to use something like abs(a - b) < myTolerance instead of a = b.

    Regards

    Hanno

  • 1. atac (Dec 07, 2010 01.09):

    hi all,

    I need you help again.. something strange happend when I search for a specific value in the array_search function I found here in this forum. See the attached image for break point results.

    In "val" there are the x,y,z coordinats 0,5,4. And in "arr" there a other coordinates of 3d points. The "exit for" command in the else part should stop the for-loop when i=5. but "i" gets to 90....?!?

    has anyone ideas how I can find out the mistake...?

    thanks for help!
    atac

    Function array_search(ByVal val, ByVal arr)
            ' searches an array for a given value
            '
            ' IN:  Variant: the value to search for
            '      Array:   the array to search
            ' OUT: Integer: the position of the value's first appearance in the array (-1 if not found)
           
            Dim i,a
            a=0
            i=0
            If isnull(val) Then
                    For i = 0 To ubound(arr)
                            If isnull(arr(i)) Then Exit For
                    Next
            Else
                    For i = 0 To ubound(arr)
                            If arr(i)(0) = val(0) And arr(i)(1) = val(1) And arr(i)(2) = val(2)  Then
                                   
                                    a = 1
                                    Exit For
                            End If
                    Next
            End If
            If i > ubound(arr) Then
                   
                    i = -1
                   
    End If
Recommend

Why are these buttons gray?