dbTalk Databases Forums  

use field names as script parameters

comp.databases.filemaker comp.databases.filemaker


Discuss use field names as script parameters in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Ursus
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 01:56 AM







"MaximalVariance" <StephenTGallagher (AT) gmail (DOT) com> schreef in bericht
news:1181223683.766613.23930 (AT) q69g2000hsb (DOT) googlegroups.com...
Quote:
Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.

-sg

Presume you have at least version 7, but better 8.5.

It has a nice function
FieldNames(fileName;layoutName)Create a layout with all fields on it (easy
enough) <AllFields>
Goto that layout
create a calc Fieldnames ( Get ( Filename) ; "AllFields" )
this will return a return delimited list with all FieldNames.
Easy enough to store and reuse, looping through the list.

Keep well, Ursus




Reply With Quote
  #12  
Old   
d-42
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 07:26 AM






On Jun 7, 6:41 am, MaximalVariance <StephenTGallag... (AT) gmail (DOT) com>
wrote:
Quote:
Hello--

I have a situation where I want the same script executed iteratively
over all fields (+500) in one particular table. (These are all
molecular structures in the same pathway and they do all belong in one
table). I am comparing the values in each field to related values in
another table, where the two tables are related by person ID. If there
is any difference between these two tables, I would like the value of
a third table to store a message like 'error' or 'match' for each of
the 500 variables. This part is all easy enough, my only dilemma is in
not wanting to hard code the variable names multiple times into each
of the scripts for each comparison. So, to summarize, has anyone
succesfully passed the field names in a databases defintion as script
parameters? Something pseudo code-ish to a "for each field y in table
x...{logic here}" where i can dynamically populate the "y's" in the
previous line.

thanks for any thoughts.

-sg
I know I'm late to the party, but here's what I'd do:
My assumptions:
You have 3 tables.
You have n=500 fields in each of Table1, table2, and table3. and you
want to evaluate:

if(Table1[n] == Table2[n])
table3[n] = "yes", else table3[n]="no"

And you want this to be done with minimal labour.

Fortunately looping through and assessing Table1[n] == Table2[n] can
be easily done; unfortunately the same is not true for Table3[n].

So, we need a hack.
I'd put all 500 hundred target fields from table3 on a layout, then:

set $counter = 1
goto field first
loop
set field = if (Evaluate["table1::field"&n&" == table2::field"&n],
"yes", "no")
exit loop if $counter=500
$counter + 1
goto field next
end loop

Now this is simplified somewhat.

You may have to set up a bit more to ensure the context is suitable
for the evaluate to work, but I don't expect that to be an issue.

Also if your fields are not conveniently numbered field1..field500 you
can pass the field names in as a list (which is easy enough to
generate), and then you can do something like this to evalutate the
nth fields:

Evaluate(
GetField(MiddleValues(table1list,counter)) & "==" &
GetField(MiddleValues(table2list,counter)
)

(Note you may have to pre-pend the "table::" references to the field
names, if they are not already in the list.)

All that said, I strongly suspect your database design is flawed if
you have 500 fields that you want to iteratively work with. They very
likely should be blown out into a separate table.

This gives you the flexibility to work with portals, which DO allow
you to directly specify the nth record, making your script a lot more
elegant. and your database design much cleaner too.

For example If I am storing 500 attributes about an entity, I usually
find it makes more sense to abstract the attributes into an 'attribute
entity'. And then instead of dragging around a datamodel with 500
fields, I have much simpler one with a basic one-many relationship
between the parent object and all its attributes. Each attribute is
simply a { parentid, attributename, value } triplet. And in this case
each parent would have 500 children. (In a perfect world, you'd
further abstract attribute name out to an attributeid, and then store
the { attribute name / attribute id } pairs in yet another table, but
that may or may not be worth the effort.

To make it concrete, lets say it was a database of people: for each
person I want to track:

home phone, cell phone, car phone, fax phone, office phone, cabin
phone, emergency phone, pager phone, boat phone, toll-free phone.

rather than create 10 or so phone fields, I'd just create a related
phonenumbers file:
{personid, phonename, phonenumber}

and it would hold things like:

{123, boat phone, 555-1234}
{123, office phone, 555-1455}

In this case you have the added flexibility of duplicating types if
you want, or leaving types out. Or you can enforce constraints so that
all 10 related records are present and filled out.

-cheers,
Dave



Reply With Quote
  #13  
Old   
Grip
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 08:24 AM



On Jun 8, 5:45 pm, Helpful Harry <helpful_ha... (AT) nom (DOT) de.plume.com>
wrote:
Quote:
In article <46698c92$0$95239$dbd49... (AT) news (DOT) wanadoo.nl>, "Ursus"



ursus.k... (AT) wanadoo (DOT) nl> wrote:
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

Although that will let you obtain a list of the names of the fields,
you can't actually use those names within other functions in place of a
field - you can't, for example, use

Set Field [VariableField, "5"]

where VariableField can take on any of the real field names that you
want to set the value of. This means you can't set the value of all
five fields called:

Field_1, Field_2, Field_3, Field_4, Field_5

by using a loop like

Set Parameter [Variable, 1]
Loop
Set Field ["Field_" & Variable, "My Value"]
Set Parameter [Variable, Variable + 1]
Exit Loop If [Variable = 6]
End Loop

You instead have to hardcode the Set Field command five times with the
actual field names.
ie.
Set Field [Field_1, "My Value"]
Set Field [Field_2, "My Value"]
Set Field [Field_3, "My Value"]
Set Field [Field_4, "My Value"]
Set Field [Field_5, "My Value"]

Harry, the OP was talking about script parameters. With 8 you can set a
variable and use this

Set Variable <$MyVariable ; MyValue
Perform Scipt <Somescript ; $MyVariable

Now you see how the variable can hold any value from the list with
fieldnmames and parse it to a second script as scriptparameter.

Yes variables are useful, but they were also wanting to use those
parameters within other functions in place of field names to access the
field's data, which as far as I can work out (and may well be wrong of
course) is not possible,
eg.
Set Field [$MyVariable, "My Value"]

or If ($MyVariable = "My Value", "Yes", "No")

where $MyVariable contains the name of a field and you want to set or
retrieve the actual data value of that field.

For example, if $MyVariable contains "MyField_1" using the above Set
Field command will not set the data of MyField_1 to "My Value". Or in
the second example the If statement will test the contents of
$MyVariable, not the contents of the field MyField_1. Both are likely
produces a "Field name expected" error when trying to exit the script /
calculation.

The way around this may be to use the variable (or a temporary field)
to store each fields value as you loop through copying the data values
from each field in sequence, but it would be a long-winded process for
500 fields. I think the best answer is more likely to be to separate
those fields into 500 records in another table.

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Variables are not limited in the way you think they are. In the two
examples above, the first wouldn't work, but that's a limitation of
Set Field, not variables. And the second would work fine, based on
the value of the field at the time you set the variable. The field
itself is not evaluated when the variable is, but rather the contents
of the variable are set to the fields contents.

I've found variables to be very robust, except for the 'repeating'
feature, which is kind of bogus.

G



Reply With Quote
  #14  
Old   
Ursus
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 11:56 AM



Quote:
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

Although that will let you obtain a list of the names of the fields,
you can't actually use those names within other functions in place of a
field - you can't, for example, use

Set Field [VariableField, "5"]

where VariableField can take on any of the real field names that you
want to set the value of. This means you can't set the value of all
five fields called:

Field_1, Field_2, Field_3, Field_4, Field_5

by using a loop like

Set Parameter [Variable, 1]
Loop
Set Field ["Field_" & Variable, "My Value"]
Set Parameter [Variable, Variable + 1]
Exit Loop If [Variable = 6]
End Loop

You instead have to hardcode the Set Field command five times with the
actual field names.
ie.
Set Field [Field_1, "My Value"]
Set Field [Field_2, "My Value"]
Set Field [Field_3, "My Value"]
Set Field [Field_4, "My Value"]
Set Field [Field_5, "My Value"]
Harry, the OP was talking about script parameters. With 8 you can set a
variable and use this

Set Variable <$MyVariable ; MyValue>
Perform Scipt <Somescript ; $MyVariable>

Now you see how the variable can hold any value from the list with
fieldnmames and parse it to a second script as scriptparameter.

Ursus




Reply With Quote
  #15  
Old   
Helpful Harry
 
Posts: n/a

Default Re: use field names as script parameters - 06-09-2007 , 07:18 PM



In article <1181395485.928770.160230 (AT) m36g2000hse (DOT) googlegroups.com>,
Grip <grip (AT) cybermesa (DOT) com> wrote:

Quote:
On Jun 8, 5:45 pm, Helpful Harry <helpful_ha... (AT) nom (DOT) de.plume.com
wrote:
In article <46698c92$0$95239$dbd49... (AT) news (DOT) wanadoo.nl>, "Ursus"



ursus.k... (AT) wanadoo (DOT) nl> wrote:
The FieldNames function has been there since at least FileMaker 4, but
unfortunately I can't see it being of any use for this problem.

Although that will let you obtain a list of the names of the fields,
you can't actually use those names within other functions in place of a
field - you can't, for example, use

Set Field [VariableField, "5"]

where VariableField can take on any of the real field names that you
want to set the value of. This means you can't set the value of all
five fields called:

Field_1, Field_2, Field_3, Field_4, Field_5

by using a loop like

Set Parameter [Variable, 1]
Loop
Set Field ["Field_" & Variable, "My Value"]
Set Parameter [Variable, Variable + 1]
Exit Loop If [Variable = 6]
End Loop

You instead have to hardcode the Set Field command five times with the
actual field names.
ie.
Set Field [Field_1, "My Value"]
Set Field [Field_2, "My Value"]
Set Field [Field_3, "My Value"]
Set Field [Field_4, "My Value"]
Set Field [Field_5, "My Value"]

Harry, the OP was talking about script parameters. With 8 you can set a
variable and use this

Set Variable <$MyVariable ; MyValue
Perform Scipt <Somescript ; $MyVariable

Now you see how the variable can hold any value from the list with
fieldnmames and parse it to a second script as scriptparameter.

Yes variables are useful, but they were also wanting to use those
parameters within other functions in place of field names to access the
field's data, which as far as I can work out (and may well be wrong of
course) is not possible,
eg.
Set Field [$MyVariable, "My Value"]

or If ($MyVariable = "My Value", "Yes", "No")

where $MyVariable contains the name of a field and you want to set or
retrieve the actual data value of that field.

For example, if $MyVariable contains "MyField_1" using the above Set
Field command will not set the data of MyField_1 to "My Value". Or in
the second example the If statement will test the contents of
$MyVariable, not the contents of the field MyField_1. Both are likely
produces a "Field name expected" error when trying to exit the script /
calculation.

The way around this may be to use the variable (or a temporary field)
to store each fields value as you loop through copying the data values
from each field in sequence, but it would be a long-winded process for
500 fields. I think the best answer is more likely to be to separate
those fields into 500 records in another table.

Variables are not limited in the way you think they are. In the two
examples above, the first wouldn't work, but that's a limitation of
Set Field, not variables. And the second would work fine, based on
the value of the field at the time you set the variable. The field
itself is not evaluated when the variable is, but rather the contents
of the variable are set to the fields contents.

I've found variables to be very robust, except for the 'repeating'
feature, which is kind of bogus.
Yes, variables are great, but they are really only a temporary storage
space.

The second example will work if the variable $MyVariable contains the
data "My Value" ... but it won't work if $MyVariable contains the data
MyField_1 and you are wanting to see if the MyField_1 field itself
contains the data "My Value".

It's this second re-direction using varibales / parameters that the
original question was about and can't be done that easily. In
programming languages like C these would be called pointers - they
don't hold the data themselves, but point to the real location where
the data is stored.

Other people have given examples using a new GetField in function that
means such re-direction may work by changing the second example to be
something like:

If (GetField($MyVariable) = "My Value" ...

This function, if it works as it appears to, could make simple
variables a lot more powerful for some uses than as simple storage
spaces.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.