| **Navigation:**  [[abc library reference.htm|ABC Library Reference]] > RuleManager > RulesCollection Class Methods >====== AddRule (add a rule to this collection) ====== | [[addcontoltorule add managed control .htm|{{btn_prev_n.gif|Previous page}}]][[abc library reference.htm|{{btn_home_n.gif|Return to chapter overview}}]][[brokenrulecount count rules in the collection which are broken.htm|{{btn_next_n.gif|Next page}}]] | | || **AddRule( **//name//,//description//,//expression//,//control//,//offset//**)** {{blk2blue.jpg|blk2blue.jpg}} | **AddRule** | Adds and initializes a rule to the collection being managed by this RuleManager object | | //name// | A string constant, variable, EQUATE, or expression that contains a name for this rule. If this name is not unique, results may be unpredictable. | | //description// | A string constant, variable, EQUATE, or expression that contains a description of this rule. The primary use of this description is as a message identifying a broken rule. The description should be worded with this use in mind. | | //expression// | A string constant, variable, EQUATE, or expression that contains the logical expression which defines this rule. If the expression evaluates to False, the rule is considered broken. | | //control// | A numeric constant, variable, EQUATE, or expression that specifies the Field Equate of the control linked to this rule. If the rule is broken, an error indicator will be placed to the right of this control. | | //offset// | A numeric constant, variable, EQUATE, or expression that specifies the distance, in dialog units, between the right side of the linked control and the error indicator. | The **AddRule **method creates a Rule object and adds it to the broken rule queue. **Example:** | **Customer RulesCollection  ** | | ** CODE  ** | | **  Customer.SetErrorImage('~BRuleNo.ico')** | | **  Customer.SetDescription('Customer File Rules')** | | **  Customer.AddRule('ShortNameReqiored','Short name is required', |** | | **                   'cus:ShortName <;<;> '''' OR CheckShortName()', | ** | | **                    ?cus:ShortName,3)** | | **  Customer.AddRule('Company Boolean','Must select individual (0) or company (1)', |** | | **      'INRANGE(cus:Company,0,1)',?cus:Company,3) ** | | **  Customer.AddRule('CompanyNameRequired','Company name is required', |** | | **                   'cus:CompanyName <;<;> '''' OR NOT cus:Company',?cus:CompanyName,3)** | | **  Customer.AddRule('LastNameRequired','Last name is required', |** | | **                   'cus:LastName <;<;> '''' OR cus:Company',?cus:LastName,3)** | | **  Customer.AddRule('CityRequired','City is required','cus:City <;<;> ''''',?cus:City,3)** | | **  Customer.AddRule('StateRequired','State is required','cus:State <;<;> ''''',?cus:State,3)** | | **  Customer.AddRule('ZipOK','Postal code must have valid format.',** | | **                   'CheckCustomerZip()',?cus:ZipCode,3)  ** | | **  Customer.AddRule('CreditLimit','Credit limit must not exceed $1000.00',** | | **                   'cus:CreditLimit =<;<; 1000',?cus:CreditLimit,3)** | | |