Share via


Style.SetResults 方法 (Visio)

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

語法

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

表達 代表 Style 物件的變數。

參數

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

傳回值

整數

註解

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

針對 Style 物件,您可以使用 SetResults 方法來設定任何一組單元格的結果。 您可以在 SID_SRCStream () 中傳遞整數陣列,告訴 SetResults 方法您想要設定的儲存格。 SID_SRCStream () 是 2 位元組整數的一維陣列。

針對 Style 物件,SID_SRCStream () 應該是 n>= 1 之 3 n 個 2 位元組整數的一維數位列。 SetResults 方法會將數據流解譯為:

{sectionIdx, rowIdx, cellIdx }n

其中 sectionIdx 是所要儲存格的區段索引,rowIdx 是它的資料列索引,而 cellIdx 則是它的儲存格索引。

UnitsNamesOrCodes () 陣列會控制結果中個別項目的測量單位。 此陣列中的每一個項目都可以是類似 "inches"、"inch"、"in." 或 "i" 等字串。 字串可用於所有支援的 Microsoft Office Visio 單位,例如公分、公尺、英哩等等。 您也可以使用 VisUnitCodes 中的 Visio 類型連結庫所宣告的整數常數 (visCentimetersvisInches 等) 表示所需的單位。 如需用於量值單位的常數清單,請參閱 關於量值單位。 請注意,如果在 Flags 中設定 visSetFormulas,在 UnitsNamesOrCodes () 陣列中指定的值不會有任何作用。

如果 UnitsNamesOrCodes () 不是空的,我們預期它是 1 <= u 變體的一維數位列。 每個專案都可以是字串或整數碼,或空 (不) 。 如果 i 'th entry 是空的, resultArray () 中的 i 'th 專案是以 單位指定的單位 (j) ,其中 j 是最近一個不是空的專案。 因此,如果您想要以相同的單位解譯 resultArray () 中的所有專案,您只需要傳遞具有一個專案 的 UnitsNamesOrCodes () 陣組。 如果沒有先前不是空的專案,或未提供 單位 陣列,則會使用 visNumber (0x20) 。 這會導致應用程式預設為內部單位 (,就像 Cell 物件的 ResultIU 屬性) 一樣。

resultArray () 參數應該是 1 <= m 變體的一維陣列。 結果可以傳遞為 DoubleIntegerStringString 的參考。 只有在 Flags 中設定 visSetFormulas 時,才會接受字串,在此情況下,字串會解譯為公式。 如果 resultArray (i) 是空的, 則 i 'th 單元格會設定為 resultArray (j) 中的值,其中 j 是最近一個不是空的專案索引。 如果沒有先前不是空的專案,則不會更改對應的單元格。 如果指定的結果少於儲存格, (如果 m < n) ,i 'th cell , i < m , 會設定為與 m 'th 單元格相同的值。 因此,若要將許多儲存格設定為相同的值,您只需要傳遞一份值。

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

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

SetResults 方法傳回的值是SID_SRCStream () 中已成功處理的項目數。 如果 i < n 個專案已正確處理,但 i + 1 項目發生錯誤, 則 SetResults 方法會引發例外狀況並傳回 i。 否則會傳回 n

範例

下列範例示範如何使用 SetResults 方法。 本範例假設有一個使用中頁面,其上至少有 3 個圖形。 它會使用 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 支援與意見反應