In the following example, we are going to manipulate objects in collections by creating business rule objects and attaching them to a class object. To do so, we :
Create the business rule objects
Initialize their attributes
Retrieve the first object in the class attributes collection
Add the created rules at the beginning and at the end of the attached rules collection
Move a rule at the end of the the attached rules collection
Remove a rule from the attached rules collection
If (not ExistingModel Is Nothing) and (not FoundClass Is Nothing) Then ' We are going to create business rule objects and attached them to the class ' Create first the business rule objects Dim Rule1, Rule2 Set Rule1 = ExistingModel.BusinessRules.CreateNew() Set Rule2 = ExistingModel.BusinessRules.CreateNew() If (not Rule1 is Nothing) And (not Rule2 Is Nothing) Then output "Business Rule objects have been successfully created" ' Initialize rule attributes Rule1.SetNameAndCode "Mandatory Name", "mandatoryName" Rule1.ServerExpression = "The Name attribute cannot be empty" Rule2.SetNameAndCode "Unique Name", "uniqueName" Rule2.ServerExpression = "The Name attribute must be unique" ' Retrieve the first object in the class attributes collection Dim FirstAttr, AttrColl Set AttrColl = FoundClass.Attributes If not AttrColl is Nothing Then If not AttrColl.Count = 0 then Set FirstAttr = AttrColl.Item(0) End If End If Set AttrColl = Nothing If not FirstAttr is Nothing Then output "First class attribute successfully retrieved from collection" ' Add Rule1 at end of attached rules collection FirstAttr.AttachedRules.Add Rule1 ' Add Rule2 at the beginning of attached rules collection FirstAttr.AttachedRules.Insert 0, Rule2 ' Move Rule2 at end of collection FirstAttr.AttachedRules.Move 1, 0 ' Remove Rule1 from collection FirstAttr.AttachedRules.RemoveAt 0 Set FirstAttr = Nothing End If End If Set Rule1 = Nothing Set Rule2 = Nothing End If