Referencing a field name as a variable

A field name should be able to be referenced as a variable. Am I missing something here?

Local LFieldName
LFieldName = "physical_address1"
Field LFieldName

To quote the help page for the field statement:

If fieldname is a field or variable which contains the name of the field you wish to move to you must enclose it inside parentheses so that Panorama treats fieldname as a formula and not a literal value.

So use:

Field (LFieldName)

You could also use

Field ""+LFieldName

or

Field LFieldName+""

By all rights

Field physical_address1

shouldn’t work, but it does, and that fact means that you have to do something extra when the variable is meant to be a formula, and not the literal field name.

Good catch Dave. In my testing for why it was not working, I knew that the literal naming of the field would work, and that is what threw me (though I most often use chevrons).

Thanks all

What is the easy answer for why this does not work?

Select SizeOf(«») > 0

In this case, the parameter must be a formula.

Select sizeof(info(“fieldname”))>0

Yes that work around will work. I had figured that out but I was looking for what I was missing in the docs.

Thank you Dave.

The «» notation works in applications where you want the contents of the field. For example

«»*2

means "take the contents of the current field and multiply it by two.

However, in some situations you are not dealing with the contents of the field, but rather the name of the field. This is the case for the field statement and the sizeof( function.

For example, consider the code:

field "Address"

This tells Panorama to jump to the Address field. The quoted text specifies the name of the field to jump to.

Now suppose you used this code:

field Address

According to Panorama’s normal formula rules, what this should mean is “take the contents of the Address field, and jump to that field”. Probably not what you want. So the field statment has a special trick - if the formula is nothing but a single identifier, then jump to that identifier, not to the contents of that identifier. Since this is what you want over 99% of the time, everyone is almost always happy.

But this trick only is applied if the formula is nothing but a single identifier. If the formula is any more complicated than that, Panorama handles the formula like any other formula. So

field (Address)

means take the contents of the Address field and jump to that, and so does

field Address+""

The trick only works if the field name is used alone, all by itself.

The sizeof( function has the same trick. Again, this function uses the name of the field or variable, not the contents. Without this trick, you would have to say:

sizeof("Address")

But with this trick you can say

sizeof(Address)

Well, this trick only works on actual field names. I suppose it could be extended to work on «» as well, but that hasn’t happened.

This is new to Panorama X. In Panorama 6 you were required to use

sizeof("Address")

The datatype( function is similar.

To be fair, it’s been ten years now. Does that still count as new? :thinking:

It does if you have been religiously applying the old rules for the last ten years.