calculations...again

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

calculations...again

Postby RobertMeyer » Thu Jun 10, 2004 8:28 pm

i have some code that calculates a value based on a parameter;

i envision having several calculated fields on a form, and
each of them would call this common calculation, passing
a paramater specifiec to each of them, and each field would display
the results of the calculation on the form.

however, i can't pass an argument to a calculation, so that idea
is out.

i seem to remember reading on the forum that i'ts NOT ok for
a calculated field to call a global method (correct me if i'm wrong),
so the idea of a global method containing the formula is out as well.

it seems that the only option i have, is to have all 4 calculated fields
on the form each have their own copy of the formula, which breaks
all the rules of good programming practice.

can anyone tell me of a better way to do this in servoy?
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby maarten » Fri Jun 11, 2004 6:29 am

Can't you do something like this:
1) change your calculated fields into plain integer/number(?) fields.
2) create global script with the formula
3) create onShow script in the form that looks like:
myDatabaseColumn1 = globals.myFormula(myParameterx);
myDatabaseColumn2 = globals.myFormula(myParametery);
etc...

note: of course your calculation fields will now only be filled/refreshed after actually opening the form. (I can't oversee from here if this would cause inconsistency in your solution)
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby jcompagner » Fri Jun 11, 2004 11:00 am

if you have a common script that you want to call in calculations. Just make a global method and call that one. (globals.methodName(arguments))

you can't see that in the tree but it will work fine as long as you don't do there things like accessing forms and/or elements ect.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby RobertMeyer » Fri Jun 11, 2004 4:02 pm

maarten wrote:note: of course your calculation fields will now only be filled/refreshed after actually opening the form. (I can't oversee from here if this would cause inconsistency in your solution)


that's basically the approach i'm considering, but as you noted,
my fields won't automatically update (which is the real beauty
of calculated fields).

so it looks like i'll have to emulate the calculation concept, and
have a method that gets called when any of the fields containing
the input parameters changes.

thanks for helping me think this thru.

rm.
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby maarten » Fri Jun 11, 2004 7:52 pm

so it looks like i'll have to emulate the calculation concept, and
have a method that gets called when any of the fields containing
the input parameters changes.

well, in fact if you follow johan's suggestion, you can keep your calculation and fill it with:

Code: Select all
var exampleArgument = x + y //or what ever
return globals.myFormula(exampleArgument , myDatabaseColumn, etc...);
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby RobertMeyer » Sat Jun 12, 2004 6:17 pm

jcompagner wrote:if you have a common script that you want to call in calculations. Just make a global method and call that one. (globals.methodName(arguments))

you can't see that in the tree but it will work fine as long as you don't do there things like accessing forms and/or elements ect.


actually, that would be great. i assumed since i couldn't see global methods
in the tree that it was not a good idea to call them. that helps a great deal.

are there any other restrictions when calling global methods from a calculation?
like, can i use relations to get data from other tables?
can i do sql queries?

thanks.
rm
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm

Postby jcompagner » Sun Jun 13, 2004 11:41 am

out of my head:

Everything can be done in such a global method, Except everything under the "forms" node.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby RobertMeyer » Sun Jun 13, 2004 2:55 pm

jcompagner wrote:Everything can be done in such a global method, Except everything under the "forms" node.


got it. thanks.
RobertMeyer
 
Posts: 268
Joined: Sat Dec 27, 2003 9:05 pm


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 30 guests

cron