共用方式為


Visio) (ValidationRule.TestExpression 屬性

會取得或設定判斷目標物件是否滿足驗證規則的邏輯運算式。 讀取/寫入。

語法

expressionTestExpression

表達 代表 ValidationRule 物件的 變數。

傳回值

字串

註解

當您呼叫Validate方法或按一下 [進程] 索引標籤上的 [檢查圖表] 來驗證圖表時,Microsoft Visio 會使用您設定為TestExpression屬性值的測試運算式來判斷目標物件是否符合驗證規則。 如果測試運算式評估結果為 False,Visio 會產生驗證問題。 如果測試運算式評估為 True,則不會產生任何驗證問題。

只有當ValidationRule物件的FilterExpression屬性值評估為 True 時,Visio 才會評估目標物件的測試表達

TestExpression 屬性值的語法與 ShapeSheet 運算式的語法相同。 當您設定 TestExpression 屬性值時,Visio 不會檢查測試運算式的語法。 如果測試運算式的語法不正確,驗證期間的運算式評估就會失敗,而 Visio 會在失敗時產生驗證問題。

範例

下列 Visual Basic for Applications (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 支援與意見反應