- Michael Connell
- PowerBuilder
- Tuesday, 5 October 2021 07:49 AM UTC
Hi,
We have inherited a legacy PB application and I am currently going through the code refactoring and generally tidying up.
In the code there are numerous places where the UpperBound() function is used to check the length of an array before accessing an element in that array so as to avoid an array out of bounds error:
IF UpperBound(ls_array) >= x THEN
IF ls_array[x-1] = "Some value" THEN ls_array[x] = "Some other value"
END IF
This seems unnecessarily "clunky" and I was wondering if there was a "cleaner" method.
In C# I would have used the conditional AND (&&) in such a situation but this is not available in PB.
I considered using TRY CATCH but there is no derived type ArrayOutOfBounds forcing me to use RuntimeError which seems like overkill:
Is there a better way?
Regards,
Michael Connell.
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.