會取得或設定判斷目標物件是否滿足驗證規則的邏輯運算式。 讀取/寫入。
語法
expression。 TestExpression
詞 一個代表 ValidationRule 物件的變數。
傳回值
字串
註解
當你透過呼叫 Validate 方法或點擊 Process 標籤中的檢查圖來驗證圖表時,Microsoft Visio 會使用你設定為 TestExpression 屬性值的測試表達式來判斷目標物件是否符合驗證規則。 如果測試運算式評估結果為 False,Visio 會產生驗證問題。 若測試表達式評估為 True,則不會產生驗證問題。
Visio 只有在 ValidationRule 物件的 FilterExpression 屬性值為 True 時,才會評估目標物件的測試表達式。
TestExpression 屬性值的語法與 ShapeSheet 運算式的語法相同。 當您設定 TestExpression 屬性值時,Visio 不會檢查測試運算式的語法。 如果測試運算式的語法不正確,驗證期間的運算式評估就會失敗,而 Visio 會在失敗時產生驗證問題。
範例
以下 Visual Basic 應用程式 (VBA) 範例展示了如何利用 TestExpression 屬性判斷特定形狀目標是否符合驗證規則。
' Add a validation rule to the document.
Set vsoValidationRule = vsoValidationRuleSet.Rules.Add("Unglued2DShape")
vsoValidationRule.Category = "Shapes"
vsoValidationRule.Description = "This 2-dimensional shape is not connected to
any other shape."
vsoValidationRule.Ignored = False
vsoValidationRule.TargetType = Visio.VisRuleTargets.visRuleTargetShape
' The validation function Is1D() returns a Boolean value that indicates
' whether the shape is 1D (True) or 2D (False).
vsoValidationRule.FilterExpression = "NOT(Is1D())"
' The validation function GLUEDSHAPES returns a set of
' shapes glued to the shape.
' It takes as input one parameter that indicates the direction of the glue.
' The direction values are equivalent to members of VisGluedShapesFlags:
' 0 = visGluedShapesAll1D, and 3 = visGluedShapesAll2D
' It takes as input one parameter indicating the direction of the glue.
' The validation function AGGCOUNT takes a set of shapes as its input, and
' returns the number of shapes in the set.
vsoValidationRule.TestExpression = "AGGCOUNT(GLUEDSHAPES(0)) + AGGCOUNT(GLUEDSHAPES(3)) > 0"
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。