You need to be logged in to view a user's profile.
  1. Dan Cooperstock
  2. PowerBuilder
  3. Friday, 19 January 2024 16:42 PM UTC

I need to test whether the value in a variable of type "any" is an array or not.

What I have found out is that UpperBound(vbl) returns -1 if it's not an array.

That's at least arguably consistent with the documentation, which says (of the 2nd argument n, the dimension you want the upperbound of) "If n is greater than the number of dimensions of the array, UpperBound returns -1."

So since if you don't provide that 2nd argument, it defaults to 1, and thus it makes sense that if the number of dimensions of the variable is less than 1, i.e. it's not an array, the function returns -1.

Does that seem like a reliable test? I have some code that crashes if I accidentally pass in an array (but can be modified to handle it if I know it's an array!) so I need this test.

BTW I have also observed that ClassName(vbl), when vbl refers to an array, often crashes PB. (That's in PB 2021 Build 1509.)

Thanks.

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 18:29 PM UTC
  2. PowerBuilder
  3. # 1

Hi Dan;

  Yes, the UpperBoumd() method would be the best test on any variable that might / might not be, in an array! If you have what you think is a proper use reproducible ClassName() error Test Case App - please open a Support Ticket.  Note that my STD Framework - and the PFC framework for that matter - use the ClassName ( ) method all over the place and for my framework, I have never had this issue - ever. Of course, the "context" of that command's use could be the trigger.  ;-)

Regards .. Chris

Comment
There are no comments made yet.
Dan Cooperstock Accepted Answer Pending Moderation
  1. Friday, 19 January 2024 19:51 PM UTC
  2. PowerBuilder
  3. # 2

Thanks. It would be good to clarify this functionality of UpperBound in the Help. Although I can see how it's arguably implied by the part I quoted, explicitly stating "Calling UpperBound on a non-array argument will return -1 for any value of n" or words to that effect.


It seems that Classname on an array of simple variables like strings doesn't crash PB, but calling it on an array of structures or nvo's does. I'll submit a bug.

Comment
  1. Chris Pollach @Appeon
  2. Friday, 19 January 2024 20:13 PM UTC
Hmmm, I am pretty sure if that would NOT be Kosher using the ClassName () method on an array. However, I think then that A) That should be in the documentation on that method and B) The PB compiler should catch that at compile time (IMHO).
  1. Helpful
  1. Dan Cooperstock
  2. Friday, 19 January 2024 21:15 PM UTC
On arrays of simple types, Classname just returns the name of the type. Like returning "string" when used on a string array variable. I would argue that's not the most desirable behaviour (I'd prefer it to return something like "string[]") but I expect changing that would break someone's code! :)
  1. Helpful
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.