共用方式為


Page.SetResults 方法 (Visio)

會設定一個或多個儲存格的結果或公式。

語法

運算式SetResults( _SID_SRCStream()_ , _UnitsNamesOrCodes()_ , _resultArray()_ , _Flags_ )

一個代表 頁面 物件的變數。

參數

名稱 必要/選用 資料類型 描述
SID_SRCStream () 必要 整數 識別要修改之儲存格的陣列。
單位名稱或代碼 () 必要 Variant 歸類結果陣列中的項目所用的度量單位。
結果陣列 () 必要 Variant 要指派給識別的儲存格之結果或公式。
Flags 必要 整數 會影響 SetResults 行為的旗標。

傳回值

整數

註解

SetResults 方法就像 Cell 物件的 Result 方法,但是有一點例外,就是可以使用這個方法一次設定很多儲存格的結果 (值),而不是一次設定一個儲存格的結果 (值)。

如果是 Page 物件,您可以使用 SetResults 方法,在頁面或主圖形的任何一組圖形中設定任何一組儲存格的結果。

你透過傳遞整數陣列,告訴 SetResults 方法你想設定哪些儲存格_SID_SRCStream () 。 SID_SRCStream () 是一個一維的 2 位元組整數陣列。

對於 頁面 物件, SID_SRCStream () 應是一個一維陣列,包含 4 個 n 個 2 位元組整 數,n>=1。 SetResults 方法將串流解讀為:

{sheetID, sectionIdx, rowIdx, cellIdx }n

其中的 sheetID 為頁面或主圖形上的 Shape 物件的 ID 屬性 (要修改此頁面或主圖形的儲存格結果)。

如果條目中的 sheetIDvisInvalShapeID (-1) ,或 是sectionIdx 的底部位元組是 visSectionInval (255) ,則該條目會被 SetResults 方法忽略。 其背後的動機是,同一 SID_SRCStream () 陣列可用於多個呼叫 SetResultsGetResults 及類似方法,呼叫者只需在呼叫間對串流做些微調整即可。

UnitsNamesOrCodes () 陣列控制結果中各個條目所屬的測量單位。 此陣列中的每一個項目都可以是類似 "inches"、"inch"、"in." 或 "i" 等字串。 字串可用於所有支援的 Microsoft Office Visio 單位,如公分、公尺、英里等。 你也可以用整數常數 (visCentimetervisInches 等單位來表示想要的單位,) Visio 類型庫在 VisUnitCode 中宣告。 關於用於度量單位的常數列表,請參見 關於度量單位。 請注意,若 visSetFormulas 設於 Flags,則 UnitsNamesOrCodes () 陣列中指定的值不會產生影響。

UnitsNamesOrCodes () 非空,則預期它是一個一維陣列,包含 1 <= u 個變體。 每個條目可以是字串或整數碼,或空 (無) 。 如果第 i 個項目是空的,resultArray () 中的第 i 個項目會被單位 (j) 所指定的單位,其中 j 是最近一次且不空的前一個項目。 因此,如果你想讓 resultArray () 的所有項目都以相同的單位來解讀,你只需要傳遞一個只有一個項目的 UnitsNamesOrCodes () 陣列。 若先前無非空的輸入,或未提供 單位 陣列,則使用 visNumber (0x20) 。 這會導致應用程式預設為內部單元 (,Cell 物件的 ResultIU 屬性亦) 。

resultArray () 參數應為一維陣列,包含 1 <= m 個變體。 結果可以以 DoubleIntegerString 或指向 字串的參考方式傳遞。 字串僅在 visSetFormulas 被設定為 Flags 時才被接受,此時字串會被解讀為公式。 如果 resultArray (i) 為空,第 i 個儲存格會設為 resultArray (j) 中的值,其中 j 是最近一次非空的前一項目的索引。 如果沒有先前的條目不是空的,則對應的格子不會被更改。 若指定結果少於格子數 (若 m < n ) ,第 i 個格子 i < m 會被設定為與 第 m 個格子相同的值。 因此,要將多個儲存格設為相同值,只需傳遞一份該值副本即可。

Flags 參數應是下列值的位元遮罩。

常數 描述
visSetFormulas &H1 將結果中的字串視為公式。
visSetBlastGuards &H2 覆寫目前的儲存格值 (即使這些值有受到保護)。
visSetTestCircular &H4 測試儲存格循環參考的建立。
visSetUniversalSyntax &H8 公式在通用語法中。

SetResults 方法回傳的值是成功處理的 SID_SRCStream () 條目數量。 如果 i < n 個項目處理正確,但在 i + 第一個項目發生錯誤, SetResults 方法會觸發例外並回傳 i。 否則 ,n 會被回傳。

範例

以下範例說明如何使用 SetResults 方法。 這個例子假設有一個至少有三個圖形的活躍頁面。 它使用 GetResults 方法來取得形狀 1 的寬度、形狀 2 的高度和形狀 3 的角度。 接著它使用 SetResults 將形狀 1 的寬度設定為形狀 2 的高度,以及形狀 2 的高度設定為形狀 1 的寬度。形狀 3 的角度保持不變。

這個範例會使用 Page 物件的 GetResults 方法來取得 3 個儲存格公式,並使用相同物件的 SetResults 方法來設定公式。 輸入陣列對於每一個儲存格會有 4 個空位,Master 物件也是同樣的情形。 如果是 ShapeStyle 物件,則每一個儲存格只需要 3 個空位 (區段、資料列及儲存格)。

 
Public Sub Set Results_Example() 
 
 On Error GoTo HandleError 
 
 Dim aintSheetSectionRowColumn(1 To (3 * 4)) As Integer 
 aintSheetSectionRowColumn(1) = ActivePage.Shapes(1).ID 
 aintSheetSectionRowColumn(2) = visSectionObject 
 aintSheetSectionRowColumn(3) = visRowXFormOut 
 aintSheetSectionRowColumn(4) = visXFormWidth 
 
 aintSheetSectionRowColumn(5) = ActivePage.Shapes(2).ID 
 aintSheetSectionRowColumn(6) = visSectionObject 
 aintSheetSectionRowColumn(7) = visRowXFormOut 
 aintSheetSectionRowColumn(8) = visXFormHeight 
 
 aintSheetSectionRowColumn(9) = ActivePage.Shapes(3).ID 
 aintSheetSectionRowColumn(10) = visSectionObject 
 aintSheetSectionRowColumn(11) = visRowXFormOut 
 aintSheetSectionRowColumn(12) = visXFormAngle 
 
 'Get the first two values in inches. The second element in 
 'the units array is left uninitialized (empty) because we 
 'want the second result in the same units as the first 
 'result. The third result is initialized in degrees. Note that 
 'units can be expressed as a string or an integer constant. 
 Dim avarUnits(1 To 3) As Variant 
 avarUnits(1) = "in." 
 avarUnits(3) = visDegrees 
 
 'Return results of cells as an array of floating point numbers. 
 Dim avarResults() As Variant 
 ActivePage.GetResults aintSheetSectionRowColumn, visGetFloats, _ 
 avarUnits, avarResults 
 
 'Use SetResults to: 
 
 ' - Set the width of shape 1 to the height of shape 2. 
 
 ' - Set the height of shape 2 to the width of shape 1. 
 
 'NOTE: avarResults() is indexed from 0 to 2. 
 
 Dim varTemp As variant 
 varTemp = avarResults(0) 
 avarResults(0) = avarResults(1) 
 avarResults(1) = varTemp 
 
 'Pass the same array back to SetResults that we 
 'just passed to GetResults, but leave the angle 
 'alone. By setting the sheet ID entry in the third 
 'slot of the aintSheetSectionRowColumn array to 
 'visInvalShapeID, we tell SetResults to ignore that slot. 
 aintSheetSectionRowColumn(9) = visInvalShapeID 
 
 'Set the results of the cells. 
 ActivePage.SetResults aintSheetSectionRowColumn, avarUnits, avarResults, 0 
 
 Exit Sub 
 
HandleError: 
 
 MsgBox "Error" 
 
 Exit Sub 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應