Page 1 of 1

uf_add_unique_element_to_array()

PostPosted: 16 Apr 2013, 14:16
by Ursego
The function adds new value to a string array but only if that value doesn't exist in it yet. So, if the whole array is populated with help of this function, then, finally, all its elements will be unique. You need to have the function uf_value_exists_in_array() prior to adding uf_add_unique_element_to_array(). Create overloads fot other data types if needed.

Code: Select all
/**********************************************************************************************************************
Acc:   public
-----------------------------------------------------------------------------------------------------------------------
Dscr:   Adds new value to a string array but only if that value doesn't exist in it yet.
      So, if the whole array is populated with help of this function, then, finally, all its elements will be unique.
-----------------------------------------------------------------------------------------------------------------------
Arg:   as_val - added value
      rs_arr[] (ref) - array to add value to
-----------------------------------------------------------------------------------------------------------------------
Thr:   n_ex- see http://forum.powerbuilder.us/viewtopic.php?f=2&t=1
**********************************************************************************************************************/
long         ll_new_upper_bound
DataStore   lds_temp

if this.uf_value_exists_in_array(as_val, rs_arr[]) then
   return
end if

ll_new_upper_bound = UpperBound(rs_arr[]) + 1
rs_arr[ll_new_upper_bound] = as_val

return