Using a field name as a parameter

I had several subroutines that were all the same except for an arrayselectedbuild statement. I thought I would consolidate them into one subroutine. But I need to use different fields for the arrayselectedbuild. I thought the best way to do this was to use another parameter in the calling statement. Such as:

callwithin myMiniProcedures,NewAutoEntry,"Fender","Item"

The field name is - Item - ,without the dashes. The second parameter (“Item”) being the field name I want to use in the arrayselectedbuild. I first tried,

arrayselectedbuild lvMyArray, ¶,"",parameter(2)

which didn’t work. I’ve tried many other ways, but no joy.

I finally worked around the problem by using a few “if” statements, like

if parameter(2) = "Item" 
arrayselectedbuild lvMyArray, ¶,"",Item
endif

But I doubt that is the most efficient way.

Is there a way to use a parameter directly in the arryselectedbuild statement?

That gave you an array filled with the text Item, right?

The last parameter of the arrayselectedbuild statement is a formula. A single field name is a valid formula, so using the field name like this works fine:

arrayselectedbuild lvMyArray, ¶,"",Item

In this case, the formula itself is: Item

But when you try to use parameter(2) as the formula, the formula is, literally, parameter(2), not Item. Sure, the result of the formula parameter(2) IS Item, but arrayfilter is using the formula itself, not the result of the formula. It takes the literal text of the formula, in this case parameter(2), and runs it over and over again for each selected record in the database. But what you want is to run the formula Item over and over again.

There are a couple of ways to do this. One would be to use the execute statement, like this:

execute {arrayselectedbuild lvMyArray, ¶,"",}+parameter(2)

What’s happening here is that the code we need, with the formula Item, is being constructed on-the-fly and then run immediately. In Panorama 6 this would have been the only way to solve this problem. But in Panorama X we can take advantage of the fact that the arrayselectedbuild( function takes the formula as a text parameter.

lvMyArray = arrayselectedbuild(¶,"",parameter(2))

Notice that the last parameter of the arrayselectedbuild( function IS NOT QUOTED. Usually you want to quote this formula because you are literally including it in the code. But in this case, the formula itself is calculated by a formula, so you don’t want to use quotes.

Unfortunately this has a bit of a “who’s on first?” feel to it, but if you walk thru it slowly hopefully it will all make sense.

Exactly.

Jim, thank you for your explanation and answer. I thought the best I could get was the answer—but you walked me through everything—that is so great! I even understand most of it. (I think!) Thanks to you (and others like you) this forum is absolutely wonderful!

2 Likes