1. Michael Connell
  2. PowerBuilder
  3. 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.

Michael Connell Accepted Answer Pending Moderation
  1. Thursday, 7 October 2021 07:01 AM UTC
  2. PowerBuilder
  3. # 1

Guys,

Thank you very much for all your replies.

I guess I'll just have to stick with using UpperBound() for the time being.

Regards,

Michael Connell.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 6 October 2021 09:46 AM UTC
  2. PowerBuilder
  3. # 2

I know this is not an answer to your question, but just a tip:

Sometimes, when working with arrays, I replace them with the use of a datastore. It has lots of advantages over the use of arrays.

regards

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 13:55 PM UTC
  2. PowerBuilder
  3. # 3

Hi Michael;

  IMHO - The UpperBound command is still the best implementation in PB for this.

Regards ... Chris

 

Comment
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Tuesday, 5 October 2021 09:53 AM UTC
  2. PowerBuilder
  3. # 4

Hi Michael,

conditional (lazy) AND would indeed be the clean way to write that code but it is not available in PB.

I would open a feature enhancement ticket for Appeon.

Try catch for handling array upperbound is in fact too much.

Best,

.m

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.