Welcome, Guest. Please Login or Register.
eccoMAGIC Forums
04/19/24 at 23:37:01
News: If you outline, checkout the new outlineZOOM extension. Amazing stuff to instantly bring your ideas into focus.
Home Help Search Login Register


Pages: 1
Send Topic Print
  Rating
Rate:
Rating:
Rating: 8.00
Votes: 1

5
4
3
2
1








1



5
4
3
2
1


1


2


3


4


5


6


7


8


9


10

LUA Rule to Calculate Folder Values with Circular Reference (Popularity: 4014 )
rb
Senior Member
****


I Love Ecco!

Posts: 88
Show the link to this post LUA Rule to Calculate Folder Values with Circular Reference
03/09/08 at 22:46:47
 
The approach can be used to set up a rule that
calculates values in one folder based on values in another OR vice versa!
 
Download the attached Ecco file, to explore!
 
For example, we may have the simple relation:
Cost=Rate*Hrs where Cost is in one folder and Hrs is in another.
If we change Cost, we want EccoExt to calculate the resulting Hrs
(=Cost/Rate)
If we change Hrs, we want EccoExt to calculate the resulting
Cost(=Rate*Hrs)
 
I setup 4 number folders:
Cost, Hrs, PrCost, PrHrs
 
PrCost & PrHrs are dummy folders that holds the previous values (only used
for the LUA Rule to work). The LUA script is then copied into any folder as an "Auto Assign Rule"
(e.g. Folder named "LUA_Rules"). The two columns Cost and Hrs are added to the Notepad (e.g. My Projects)
 
If you set the Cost=1,000, Hrs is calculated to 20. If you then change Hrs to 30, Cost is calculated to 1,500, etc. Try doing this in Excel!
 
LUA Script to Copy:
 
++:L:
cRate=50     -- The Rate is $50/Hr
vCost=get_folder_value("Cost",item_id)
vHrs=get_folder_value("Hrs",item_id)
vPrCost=get_folder_value("PrCost",item_id)     -- Get Previous Value
vPrHrs=get_folder_value("PrHrs",item_id)         -- Get Previous Value
 
if vPrCost~=vCost then         -- Cost changed => Calulate Hrs & set new PrCost, PrHrs
   vHrs=vCost/cRate
   set_folder_value("Hrs",item_id,vHrs)
   set_folder_value("PrHrs",item_id,vHrs)  
   set_folder_value("PrCost",item_id,vCost)
elseif vPrHrs~=vHrs then       -- Hrs Changed => Calulate Cost & set new PrCost, PrHrs
   vCost=vHrs*cRate
   set_folder_value("Cost",item_id,vCost)
   set_folder_value("PrCost",item_id,vCost)
   set_folder_value("PrHrs",item_id,vHrs)
end  
 
Back to top
« Last Edit: 03/10/08 at 21:17:30 by rb »  
  IP Logged
Admin
Administrator
*****


I love Ecco!

Posts: 134
Show the link to this post Re: LUA Rule to Calculate Folder Values with Circular Reference
Reply #1 - 03/10/08 at 21:00:25
 
Off topic replies have been moved to This Thread
Back to top
 
 

The Administrator.
WWW   IP Logged
Pages: 1
Send Topic Print