Variable field names

Hi guys

I want to do something in a loop using a variable for the field name, something like...

let n = [ this would be a field, it holds the last populated field or an address block, so "4" for example]
let field_I_want = "ad"&n

newfield = field_I_want (so in this case [ad4])

I want to use the variable as a string, is this possible? I know the syntax I've used isn't correct but hopefully OK to demonstrate what I want

Thanks in advance, Richard

Hi Richard,

If I understood the question correctly, you're looking to calculate a new field using a reference to another field that is calculated using a parameter.

In this case, you can use the eval() function:

[newfield] = eval("[ad" & {n} & "]")

Here is an example ({n}=2):

select-field-by-parameter.morph (2.6 KB)

that's perfect, thank you (sorry about the poor explanation...)

this may save me a lot of 'rule' writing... i hoped there would be, I can think of lots of processes where this will help... This time all I want to do is find the last populated field of an address block & fix it in the last address field, currently, I add a field named 'lastline' then have a rule which checks the address fields in reverse order, the first non-empty field I write the field number in lastline, then have rules to populate the field based on the lastline number, then more rules to remove the content from here it comes from - very long winded (sorry I know that made boring reading :))

as always, you have the answer... i have been processing data for some 40 years, I'm an old FoxPro user... the more I get into Easymorph the more I love it, your software rocks, thank you for the reply, best regards, Richard

Check out the coalesce() function. It might be an even easier way to do what you're looking to do.

thank you, just tried it... perfect for what I need, I'm glad I reached out, each time I do I learn a better way of doing something...

The support I get from you guys is second to none, you always come back to me quickly & even provide easy-to-follow examples.

best regards, Richard

1 Like

Thank you, @Richard_Tabram!