dbTalk Databases Forums  

Problem writting a formula in 7.0

comp.databases.filemaker comp.databases.filemaker


Discuss Problem writting a formula in 7.0 in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JSL
 
Posts: n/a

Default Problem writting a formula in 7.0 - 02-11-2006 , 10:05 PM






I have set up a database for quoting jobs. I'm having problems with setting
up a formula to do the following:

I have a field with radio buttons for 1,2,3,4 and 1/4 folds. Depending on
quantities, there are different rates for 1, 2, 3, 4 and 1/4 folding. I am
able to set up for 1 fold using the "if" function (fold = 1). But when I try
to use "or" and set up the "if" (fold=2), the formula doesn't recognize
fold=2 but it does recognize when I select 1. Can anyone shed some light on
how to setup? Thanks in advance. Jim



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

Default Re: Problem writting a formula in 7.0 - 02-11-2006 , 11:02 PM






In article <NuyHf.381$Pn5.233 (AT) fe07 (DOT) lga>, "JSL"
<jimgoblue2001 (AT) hotmail (DOT) com> wrote:

Quote:
I have set up a database for quoting jobs. I'm having problems with setting
up a formula to do the following:

I have a field with radio buttons for 1,2,3,4 and 1/4 folds. Depending on
quantities, there are different rates for 1, 2, 3, 4 and 1/4 folding. I am
able to set up for 1 fold using the "if" function (fold = 1). But when I try
to use "or" and set up the "if" (fold=2), the formula doesn't recognize
fold=2 but it does recognize when I select 1. Can anyone shed some light on
how to setup? Thanks in advance. Jim
I'm guessing you trying to do something like:

Rate = If (Fold = 1, {result for 1}) or If(Fold = 2, {result for 2})

which isn't going to work due to the way that logic works within
computers work.

You can nest If functions inside each other, but that very quickly gets
messy and difficult to read.

Instead of If, you're better to use the Case function. Case is like a
multi-choice If function, so you have something like:

Rate = Case(
Fold = 1, {the result for 1},
Fold = 2, {the result for 2},
Fold = 3, {the result for 3},
Fold = 4, {the result for 4},
Fold = 1/4, {the result for 1/4}
)

This basically says that "In the case of Fold = 1 give the result {the
result of 1}, or in the case of Fold = 2 give the result of {result of
2}, etc.





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


Reply With Quote
  #3  
Old   
Bill
 
Posts: n/a

Default Re: Problem writting a formula in 7.0 - 02-11-2006 , 11:51 PM



In article <NuyHf.381$Pn5.233 (AT) fe07 (DOT) lga>,
"JSL" <jimgoblue2001 (AT) hotmail (DOT) com> wrote:

Quote:
I have set up a database for quoting jobs. I'm having problems with setting
up a formula to do the following:

I have a field with radio buttons for 1,2,3,4 and 1/4 folds. Depending on
quantities, there are different rates for 1, 2, 3, 4 and 1/4 folding. I am
able to set up for 1 fold using the "if" function (fold = 1). But when I try
to use "or" and set up the "if" (fold=2), the formula doesn't recognize
fold=2 but it does recognize when I select 1. Can anyone shed some light on
how to setup? Thanks in advance. Jim
Have a look at the Case function. That is like If with multiple criteria.

Bill


Reply With Quote
  #4  
Old   
Remi-Noel Menegaux
 
Posts: n/a

Default Re: Problem writting a formula in 7.0 - 02-12-2006 , 01:30 AM



Beware one thing though : in the Case function, where you have
successive criteria, then If Met, IfNotMet (here you put the second
criterium, and then its IfMet), when the first met criterium is reached
(in the order in which they are written in the Case formula), the Case
function stops there and does nor examine the following criterias. Which
means, you, sometimes, have to be careful in the order in which you put
your criteria.
I may try here to give an example. Say you want to give a medal M1, if
the guy is an Artist, a medal M2 if he is a surgeon, and M3 if he is
both (stupid example I know...).
- If you write (pseudo code) :
Case (guy = "Artist", M1, guy = "Surgeon", M2, guy="Artist" and
guy="Surgeon", M3, "")
then if the guy is either an Artist or a Surgeon, it will work fine. But
he is both he will never get the M3 : instead he will get M1 (the first
encountered).
- So to get correct results, you have to write :
Case (guy="Artist" and guy="Surgeon", M3, guy = "Artist", M1, guy =
"Surgeon", M2, "")
I am sure you will find better examples than me.
Remi-Noel


"Helpful Harry" <helpful_harry (AT) nom (DOT) de.plume.com> a écrit dans le message
de news: 120220061802267991%helpful_harry (AT) nom (DOT) de.plume.com...
Quote:
In article <NuyHf.381$Pn5.233 (AT) fe07 (DOT) lga>, "JSL"
jimgoblue2001 (AT) hotmail (DOT) com> wrote:

I have set up a database for quoting jobs. I'm having problems with
setting
up a formula to do the following:

I have a field with radio buttons for 1,2,3,4 and 1/4 folds.
Depending on
quantities, there are different rates for 1, 2, 3, 4 and 1/4 folding.
I am
able to set up for 1 fold using the "if" function (fold = 1). But
when I try
to use "or" and set up the "if" (fold=2), the formula doesn't
recognize
fold=2 but it does recognize when I select 1. Can anyone shed some
light on
how to setup? Thanks in advance. Jim

I'm guessing you trying to do something like:

Rate = If (Fold = 1, {result for 1}) or If(Fold = 2, {result for 2})

which isn't going to work due to the way that logic works within
computers work.

You can nest If functions inside each other, but that very quickly
gets
messy and difficult to read.

Instead of If, you're better to use the Case function. Case is like a
multi-choice If function, so you have something like:

Rate = Case(
Fold = 1, {the result for 1},
Fold = 2, {the result for 2},
Fold = 3, {the result for 3},
Fold = 4, {the result for 4},
Fold = 1/4, {the result for 1/4}
)

This basically says that "In the case of Fold = 1 give the result {the
result of 1}, or in the case of Fold = 2 give the result of {result of
2}, etc.





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



Reply With Quote
  #5  
Old   
Michael Paine
 
Posts: n/a

Default Re: Problem writting a formula in 7.0 - 02-12-2006 , 03:17 PM



Depending on the circumstances and the complexity of the calculations it
is sometimes better to write some script to do the job and have a
"calculate" button on the layout to invoke that script. This is instead
of trying to do the calculation within the very limited logic of a
formula within a calculated field.
Here is a small extract that uses Else If statements in a similar way to
your needs
------
If [ scoring::STAR_RATING=4 ]
Set Field [ scoring::OVERALL_SCORE; $bp4 ]
Else If [ scoring::STAR_RATING=3 ]
Set Field [ scoring::OVERALL_SCORE; $bp3 ]
Else If [ scoring::STAR_RATING=2 ]
Set Field [ scoring::OVERALL_SCORE; $bp2 ]
Else If [ scoring::STAR_RATING=1 ]
Set Field [ scoring::OVERALL_SCORE; $bp1 ]
Else
Set Field [ scoring::OVERALL_SCORE; .49 ]
End If
---------------
(the full script has much more complicated logic than this extract)
Remi-Noel's caution about the order of the statements (for the Case
command) also applies here.

There are plug-ins that could invoke the script after the source field
data is entered, rather than waiting for a button to be clicked -
something that would be useful in FM8+. Microsoft Access has had this
feature since version 1!

Michael Paine

JSL wrote:

Quote:
I have set up a database for quoting jobs. I'm having problems with setting
up a formula to do the following:

I have a field with radio buttons for 1,2,3,4 and 1/4 folds. Depending on
quantities, there are different rates for 1, 2, 3, 4 and 1/4 folding. I am
able to set up for 1 fold using the "if" function (fold = 1). But when I try
to use "or" and set up the "if" (fold=2), the formula doesn't recognize
fold=2 but it does recognize when I select 1. Can anyone shed some light on
how to setup? Thanks in advance. Jim



Reply With Quote
  #6  
Old   
Matt Wills
 
Posts: n/a

Default Re: Problem writting a formula in 7.0 - 02-12-2006 , 05:23 PM



Michael Paine wrote:

Quote:
There are plug-ins that could invoke the script after the source
field data is entered, rather than waiting for a button to be clicked
- something that would be useful in FM8+. Microsoft Access has had
this feature since version 1!
There have been various agitations for on-entry, on-exit, on change
events for as long as I can remember. I had those available in a
DOS-based DB called Q&A back in the late Eighties.

Meanwhile, we have Troi Activator and EventScript plugins. EventScript
is free.

Matt


Reply With Quote
  #7  
Old   
Remi-Noel Menegaux
 
Posts: n/a

Default Re: Problem writting a formula in 7.0 - 02-12-2006 , 10:31 PM



I would add also that, in my experience - at least with FMP6 - a complex
set of concatenated calculations can make, in some projects, ages to
draw the layout - as much as several seconds -, while doing the same job
in a set of scripts calling each other is MUCH faster. I saw cases where
it was 10 times faster - drawing the layout seems instantaneous -, just
in adapting the same formulas from calculations to scripts !
Remi-Noel


"Michael Paine" <mpaine (AT) tpgi (DOT) com.au> a écrit :
Quote:
Depending on the circumstances and the complexity of the calculations
it is sometimes better to write some script to do the job and have a
"calculate" button on the layout to invoke that script. This is
instead of trying to do the calculation within the very limited logic
of a formula within a calculated field.
Remi-Noel's caution about the order of the statements (for the Case
command) also applies here.



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 - 2013, Jelsoft Enterprises Ltd.