uf_value_exists_in_array() - check if array has value


Link to this posting

Postby Ursego » 16 Apr 2013, 13:23

The function reports if the value exists in the array. If the array is small (100 elements or less) then the function simply loops on it, otherwise it creates a DataStore and uses Find().

Code: Select all
/**********************************************************************************************************************
Dscr:         Reports if the value exists in the array. If the array is small (100 elements or less) then the function
            simply loops on it; otherwise, it creates a DataStore and uses Find().
***********************************************************************************************************************
Arg:         as_val
            rs_arr[] (ref)
***********************************************************************************************************************
Developer:   Michael Zuskin - LinkedIn: http://linkedin.com/in/zuskin
**********************************************************************************************************************/
long         ll_upper_bound
long         ll_row
DataStore   lds_temp

if uf_empty(as_val) then
   f_throw(PopulateError(0, "Arg as_val is empty.")) // f_throw(): http://forum.powerbuilder.us/viewtopic.php?f=2&t=1
end if

// If array is small then we can LOOP:
ll_upper_bound = UpperBound(rs_arr[])
if ll_upper_bound <= 100 then
   for ll_row = 1 to ll_upper_bound
      if rs_arr[ll_row] = as_val then
         return true
      end if
   next
   return false
end if

// The array is large - it's faster to use DataStore search:
lds_temp = uf_ds_from_array(rs_arr[]) // uf_ds_from_array(): http://forum.powerbuilder.us/viewtopic.php?f=4&t=92
lds_temp.object.val.current = rs_arr[]
ll_row = lds_temp.Find("the_val=" + as_val, 1, ll_upper_bound)
destroy lds_temp

return (ll_row > 0)
User avatar
Ursego
Site Admin
 
Posts: 120
Joined: 19 Feb 2013, 20:33


IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:




cron
free counters

eXTReMe Tracker