Custom validation rules in code
Previously in Chapter 4, you learnt that you can add custom validation rules in code. You would need to do this if the validation rule is too complex to phrase as Filter and Test Expressions. For example, you might want to ensure that there are no cycles (paths which return back to where they start from).
You could add code into a Visio add-in, but I will demonstrate how you can put some custom code into the drawing document as VBA because this will be in the document along with any rule set that you may have written using Filter Expression and Test Expression.
First, you need to listen for the RuleSetValidated
event of the document, which can be added easily to the ThisDocument
class in the VBA project. I have used the getRule()
method from Chapter 4 to ensure that there is a rule named CheckCycle
present. If there is, then the CheckCycle()
method is called.
Private Sub Document_RuleSetValidated(ByVal ruleSet As IVValidationRuleSet) Dim rule As Visio.ValidationRule...