This post will tell you how to get HFM to spot misspelled variables in rules files automatically. For example. if you write run a rule like this:
Sub Calculate
AccountList = HS.Account.List("","AList")
For Each AccountMember In AccountList
HS.Clear "A#" & AccountMem
Next
End Sub
it will clear all accounts! This is because AccountMember has been misspelled as AccountMem and HFM therefore creates a new empty variable, AccountMem. Errors like this can be very hard to spot.
However, there is a simple solution to this problem. Put Option Explicit at the start of your rules file and declare all variables with Dim. For example:
Option Explicit
Sub Calculate
Dim AccountList, AccountMember
AccountList = HS.Account.List("","AList")
For Each AccountMember In AccountList
HS.Clear "A#" & AccountMem
Next
End Sub
When this rule is calculated in a grid or form, a message like EPMHFM-102: Error executing VBScript %0 will be displayed and a message like Error executing VBScript Microsoft VBScript runtime error, Line 3:Variable is undefined: ‘AccountList’ will be written to System Messages.
Where is it best to declare variables?
In programming languages such as Java, variables can be declared when they are used like this:
int result = 1;
This is not possible in VB rules. I find it easiest to declare variables at the start of procedures:
Sub BlockByCustom1
Dim AccountList, AccountMember
Dim Custom1List, Custom1Member
:
End Sub
As I am a bit of a neat freak, I put them in alphabetical order!
What about Calc Manager?
As far as I am aware it is not possible to use Option Explicit with Calc Manager. However, if anyone knows better I would be very interested know how.