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(). You need to have the function uf_ds_from_array() prior to adding uf_value_exists_in_array().

Code: Select all
Acc:   public
Dscr:   Reports if the value exists in the array.
Arg:   as_val
      rs_arr[] (ref)
Thr:   n_ex - see http://forum.powerbuilder.us/viewtopic.php?f=2&t=1
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."))
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
   return false
end if

// Array is large - it's faster to deal with DataStore:
lds_temp = uf_ds_from_array(rs_arr[]) // 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
Site Admin
Posts: 113
Joined: 19 Feb 2013, 20:33

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

free counters

eXTReMe Tracker