PowerBuilder Functions Removing From An Array Duplicate Values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
//==================================================================== // Function: gf_array_remove_duplicate() //-------------------------------------------------------------------- // Description: Function for removing from an array duplicate values //-------------------------------------------------------------------- // Arguments: // value any a_array //-------------------------------------------------------------------- // Returns: any, one-dimensional array in case of unprocessed data types the original array is returned //-------------------------------------------------------------------- // Usage: gf_array_remove_duplicate ( any a_array ) //-------------------------------------------------------------------- // Modify History: // //==================================================================== String ls_array[], ls_array_end[], ls_etalon Long ll_array_len, ll_array[], ll_array_end[], i, j, k, ll_rtn Integer li_array[], li_array_end[] Decimal ld_array[], ld_array_end[] Blob lb_array[], lb_array_end[] Any la_array Boolean lbn_flag i = 1 j = 1 Choose Case Lower(ClassName(a_array)) Case "string" ls_array = a_array ll_array_len = UpperBound(ls_array) Do While i <= ll_array_len ll_rtn = Pos(ls_etalon, "|" + Upper(ls_array[i]) + "|") If IsNull(ll_rtn) Or ll_rtn = 0 Then ls_etalon = ls_etalon + "|" + Upper(ls_array[i]) + "|" ls_array_end[j] = ls_array[i] j = j + 1 End If i = i + 1 Loop la_array = ls_array_end Case "long" ll_array = a_array ll_array_len = UpperBound(ll_array) Do While i <= ll_array_len ll_rtn = Pos(ls_etalon, "|" + String(ll_array[i]) + "|") If IsNull(ll_rtn) Or ll_rtn = 0 Then ls_etalon = ls_etalon + "|" + String(ll_array[i]) + "|" ll_array_end[j] = ll_array[i] j = j + 1 End If i = i + 1 Loop la_array = ll_array_end Case "integer" li_array = a_array ll_array_len = UpperBound(li_array) Do While i <= ll_array_len ll_rtn = Pos(ls_etalon, "|" + String(li_array[i]) + "|") If IsNull(ll_rtn) Or ll_rtn = 0 Then ls_etalon = ls_etalon + "|" + String(li_array[i]) + "|" li_array_end[j] = li_array[i] j = j + 1 End If i = i + 1 Loop la_array = li_array_end Case "decimal" ld_array = a_array ll_array_len = UpperBound(ld_array) Do While i <= ll_array_len If i = 1 Then ld_array_end[j] = ld_array[i] j = j + 1 End If If i > 1 Then k = 1 Do While k < j lbn_flag = False If ld_array_end[k] = ld_array[i] Then lbn_flag = True Exit End If k = k + 1 Loop If Not lbn_flag Then ld_array_end[j] = ld_array[i] j = j + 1 End If End If i = i + 1 Loop la_array = ld_array_end Case "blob" lb_array = a_array ll_array_len = UpperBound(lb_array) Do While i <= ll_array_len If i = 1 Then lb_array_end[j] = lb_array[i] j = j + 1 End If If i > 1 Then k = 1 Do While k < j lbn_flag = False If lb_array_end[k] = lb_array[i] Then lbn_flag = True Exit End If k = k + 1 Loop If Not lbn_flag Then lb_array_end[j] = lb_array[i] j = j + 1 End If End If i = i + 1 Loop la_array = lb_array_end Case Else la_array = a_array MessageBox("Error", "Unexpected datatype.") End Choose Return la_array |
Good Luck!
Subscribe
Login
0 Comments
Oldest