uf_add_unique_element_to_array()

Share this topic:



Link to this posting

Postby Ursego » 16 Apr 2013, 14:16

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
User avatar
Ursego
Site Admin
 
Posts: 111
Joined: 19 Feb 2013, 20:33

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest


uf_add_unique_element_to_array()

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





free counters

eXTReMe Tracker