Page.GetResults 方法 (Visio)

會取得許多儲存格的結果或公式。

語法

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

表達 代表 Page 物件的變數。

參數

名稱 必要/選用 資料類型 描述
SID_SRCStream () 必要 整數 識別要查詢之儲存格的陣列。
Flags 必要 整數 會影響結果中傳回之項目類型的旗標。
UnitsNamesOrCodes () 必要 Variant 傳回結果所使用的度量單位陣列。
resultArray () 必要 Variant 會接收查詢儲存格之結果或公式的陣列。

傳回值

註解

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

如果是 Page 物件,您可以使用 GetResults 方法,在頁面的任何一組圖形中取得任何一組儲存格的結果。

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

{sheetID, sectionIdx, rowIdx, cellIdx }n

其中的 sheetID 為頁面上的 Shape 物件的 ID 屬性 (需要此頁面的儲存格結果)。

注意事項

如果專案中的 sheetIDvisInvalShapeID (-1) 或 sectionIdx 的底部位元組是 visSectionInval (255) ,則會忽略該專案,並在對應的結果陣列專案中傳回空的變體。 這是因為相同的 SID_SRCStream () 陣列可用於 GetResultsSetResults的數個呼叫,以及呼叫端的類似方法只需要在呼叫之間對資料流程進行微幅變更。

Flags參數會指出傳回的結果應該以何種資料類型表示。 其值應為下列其中一項。

常數 描述
visGetFloats 0 以雙精準數 (VT_R8) 形式傳回的結果。
visGetTruncatedInts 1 以截斷的長整數 (VT_I4) 形式傳回的結果。
visGetRoundedInts 2 以四捨五入的長整數 (VT_I4) 形式傳回的結果。
visGetStrings 3 以字串 (VT_BSTR) 形式傳回的結果。
visGetFormulas 4 以字串 (VT_BSTR) 形式傳回的公式。
visGetFormulasU 5 在通用語法 (VT_BSTR) 中傳回的公式。

UnitsNamesOrCodes () 參數是陣列,可控制傳回個別結果的測量單位。 此陣列中的每一個項目都可以是類似 "inches"、"inch"、"in." 或 "i" 等字串。 這些字串可用於所有支援的 Visio 單位,例如公分、公尺、英哩等。 您也可以使用 Visio 類型程式庫所宣告的整數常數 (visCentimetersvisInches等) 表示所需的單位。 請注意,當 visInchesUnitsNamesOrCodes() 時,在 Flags 陣列中指定的值沒有任何作用。

如果 UnitsNamesOrCodes () 不是 Null,應用程式預期它是 1 < = uVariants的一維陣列。 每個專案都可以是字串或整數碼,或空 (不) 。 如果 i 'th 專案是空的, i 'th 傳回的結果會以 UnitsNamesOrCodes (j) 所指定的單位傳回,其中 j 是最近一個非空白專案的索引。 因此,如果您希望所有傳回的值都位於相同的單位中,您只需要傳遞一個專案的 UnitsNamesOrCodes () 陣列。 如果沒有先前的非空白專案,或未提供 UnitsNameOrCodes () 陣列,則會使用 visNumber (0x20) 。 這會導致內部單位 (,例如要傳回的Cell物件的ResultIU屬性) 。

如果GetResults方法成功,結果會傳回從零 (0) 到n - 1 之n變數的一維陣列。 傳回的變體類型是 Flags 的函 resultArray () 參數是由GetResults方法配置的 out 引數,它會將擁有權傳回給呼叫端。 呼叫端最後應該會在傳回的陣列上執行 SafeArrayDestroy 。 請注意, SafeArrayDestroy 有清除陣列專案所參考之變體的副作用,因此會解除配置 GetResults 方法傳回的任何字串。 (Microsoft Visual Basic 和 Microsoft Visual Basic for Applications 會為您處理此)

範例

下列範例示範如何使用 GetResults 方法。 本範例假設有一個使用中頁面,其上至少有 3 個圖形。 它會使用 GetResults 方法來取得圖案 1 的寬度、圖案 2 的高度,以及圖案 3 的角度。

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

 
Public Sub GetResults_Example() 
 
 On Error GoTo HandleError 
 
 Dim intCounter As Integer 
 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 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 
 
 For intCounter = 0 To 3 
 Debug.Print avarResults(intCounter) 
 Next 
 
 Exit Sub 
 
HandleError: 
 MsgBox "Error" 
 Exit Sub 
 
End Sub

支援和意見反應

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