domiller Posted April 18, 2014 Posted April 18, 2014 I am maintaining a system which has been written by several prople over several years. A few days ago I needed to modify a routine which set global variables for each of about 40 columns in a record (so context could be switched and still access those fields). I needed to add about 15 more columns, and that sort of repetitive work doesn't appeal to me. Thus I came up with the following: Evaluate( "Let([" & Let(q=Get(LayoutTableName);ExecuteSQL(" select '$$'||fieldname||'="&q&"::'||fieldname from filemaker_fields where tablename = '"&q&"' and fieldclass = 'Normal' and fieldtype not like 'global%' order by fieldname ";"";";¶";""))&"];0)") Assigning this to a variable resluts in zero, but assigns a (global) variable for each non-null normal field in the current record. I don't know how much use this will be to anyone, but it seemed interesting enough to share.
Wim Decorte Posted April 18, 2014 Posted April 18, 2014 A couple of thoughts: - that calc is very hard to read. I would expect a good demo to clearly explain what is happening and why. There are no comments and no whitespace to follow the calc. After running this through http://www.aptworks.com/cgi-bin/calc_formatter.cgi I get this, and it is only marginally more readable Evaluate( "Let([" & Let( q = Get( LayoutTableName ); ExecuteSQL( " select '$$'||fieldname||'=" & q & "::'||fieldname from filemaker_fields where tablename = '" & q & "' and fieldclass = 'Normal' and fieldtype not like 'global%' order by fieldname "; ""; ";¶"; "" ) ) & "];0)" ) - more importantly: why would you want to declare x number of global variables in a calc? Why not do this in a loop in a script and make local variables and take advantage of the proper scope: http://www.soliantconsulting.com/blog/2014/01/all-variables-should-be-global-or-not Whatever you do with these variables, now you have to find an equally "fell swoop" method of clearing them out. So the part that I am missing is: why do you need this, and how do you clean up when you are done? 1
Ocean West Posted April 21, 2014 Posted April 21, 2014 Automatic message This topic has been moved from "Articles, Tips, Techniques & Solutions" to "Calculation Engine (Define Fields)".
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now