AnsweredAssumed Answered

Script Efficency

Question asked by martinpaulrice on Nov 23, 2009
Latest reply on Dec 11, 2009 by liquidcooled

Title

Script Efficency

Post

Hi,

 

Just finished writing my first script of more than two lines in FM Pro 10 on an iMac running OSX 10.6.2. Amazingly enough, the script works. However, I was wondering whether there's a more efficient way of writing this script other than using all the "else if"s?

 

Here's the script:

 

 

#Subtract from "From Account/Add to 'To Account"#If [Transactions::From Account Type = "Spending" and Transactions::To Account Type = "Expense"]Set Field [Budget::Current Balance; Budget::Current Balance - Transactions::Amount]Set Field (Budget 2::Current Balance; Budget 2::Current Balance + Transactions::Amount)##Variation for "From Account" being Spending and "To Account" being Savings#If [Transactions::From Account Type = "Spending" and Transactions::To Account Type = "Savings")Set Field [Budget::Current Balance; Budget::Current Balance - Transactions::Amount)Set Field (Budget 2::Current Balance; Budget 2::Current Balance + Transactions::Amount)##Variation for "From Account" being Accrual and 'To Account" being Spending#Else If [Tansactions::From Account Type = "Accrual" and Transactions::To Account Type = "Spending"]Set Field [Budget::Current Balance; Budget::Current Balance - Transactions::Amount]Set Field (Budget 2::Current Balance; Budget 2::Current Balance + Transactions::Amount)##Subtract from "From Account"/Subtract from "To Account"#Else If [Transactions::From Account Type = "Spending" and Transactions::To Account Type = "Credit Card"]Set Field [Budget::Current Balance; Budget::Current Balance - Transactions::Amount]Set Field [Budget 2::Current Balance; Budget 2::Current Balance - Transactions::Amount]##Add to "From Account"/Add to "To Account"#Else If [Transactions::From Account Type = "Credit Card" and Transactions::To Account Type = "Expense"]Set Field [Budget::Current Balance; Budget::Current Balance + Transactions::Amount]Set Field (Budget 2::Current Balance; Budget 2::Current Balance + Transactions::Amount]##Add to From Account/Add to To Account#Else If [Tansactions::From Account Type = "Income" and Transactions::To Account Type = "Spending"]Set Field [Budget::Current Balance; Budget::Current Balance + Transactions::Amount]Set Field [Budget 2::Current Balance; Budget 2::Current Balance + Transactions::Amount]End If

 Any suggestions for making this more efficient would be greatly appreciated.

 

Thanks! 

 

Outcomes