Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powerbuilder Dynamic Array Manipulation

string array[]
long lBound, uBound

lBound = LowerBound(array[]) // = 1, empty array value
uBound = UpperBound(array[]) // = 0, empty array value

array[1] = 'Item 1'
array[2] = 'Item 2'
array[3] = 'Item 3'

lBound = LowerBound(array[]) // = 1
uBound = UpperBound(array[]) // = 3

array[3] = '' //removing item 3

lBound = LowerBound(array[]) // = 1, still
uBound = UpperBound(array[]) // = 3, still (but array[3] is nulled?

I think the line 'array[3]' is wrong, but I think I've read that this should remove the array cell.

What would be the right way to remove an array cell? Does it depend on object type? (String vs Number vs Object)

Or

Can one manipulate the UpperBound value to make it work?

i.e. after removing Item 3, I want the UpperBound, or arraylength, to be 2, since this is logically correct.

like image 413
glasnt Avatar asked Mar 29 '10 05:03

glasnt


1 Answers

For variable-size arrays, memory is allocated for the array when you assign values to it. UpperBound returns the largest value that has been defined for the array in the current script. However, you can do the trick using another dynamic array.

string array2[]
int i

for i = 1 to UpperBound(array[]) - 1
    array2[i] = array[i]
next

array = array2

Then UpperBound(array[]) will be reduced by 1.

This will work for UpperBound(array[]) - 1 > 2 because powerbuilder allocates by default memory size for 3 elements when a dynamic array is declared.

like image 168
George Dontas Avatar answered Sep 21 '22 07:09

George Dontas