會取得許多儲存格的結果或公式。
語法
運算式。
GetResults( _SRCStream()_ , _Flags_ , _UnitsNamesOrCodes()_ , _resultArray()_ )
expression 一個用於表示 Shape 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| SID_SRCStream () | 必要 | 整數 | 陣列。會識別要查詢之儲存格的資料流。 |
| Flags | 必要 | 整數 | 會影響結果中傳回之項目類型的旗標。 |
| UnitsNamesOrCodes () | 必要 | Variant | 會傳回結果所使用之度量單位的陣列。 |
| resultArray () | 必要 | Variant | 輸出參數。 會接收結果或查詢之儲存格公式的陣列。 |
傳回值
無
註解
GetResults 方法就像 Cell 物件的 Result 屬性,但是有一點例外,就是可以使用這個方法一次取得很多儲存格的結果 (值),而不是一次取得一個儲存格的結果 (值)。
如果是 Shape 物件,您可以使用 GetResults 方法來取得任何一組儲存格的結果。
SID_SRCStream () 是 2 位元組整數的陣列。 對於 Shape 物件,SID_SRCStream () 應該是 n>= 1 的 3 n 個 2 位元組整數的一維陣列。 GetResults 方法會將SID_SRCStream () 解譯為:
{sectionIdx, rowIdx, cellIdx }n
其中 sectionIdx 是所要儲存格的區段索引,rowIdx 是它的資料列索引,而 cellIdx 則是它的儲存格索引。
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 類型程式庫所宣告的整數常數 (visCentimeters、 visInches 等 ) 來表示所需的單位。 請注意,當 visInches 為 UnitsNamesOrCodes() 時,在 Flags 陣列中指定的值沒有任何作用。
如果 UnitsNamesOrCodes 不是 Null,應用程式預期它是 1 <= u變體的一維陣列。 每個項目都可以是字串或整數代碼,或空白 (沒有任何) 。 如果第 i 個項目是空的,則會以 UnitsNamesOrCodes 指定的單位傳回第 i 個傳回結果 (j) ,其中 j 是最近的前一個非空項目的索引。 因此,如果您希望所有傳回值都使用相同的單位,則只需要傳遞具有一個項目的 UnitsNamesOrCodes () 陣列。 如果沒有先前的非空項目,或如果沒有提供 UnitsNameOrCodes () 陣列,則使用 visNumber (0x20) 。 這會導致傳回內部單位 (,例如 Cell 物件的 ResultIU 屬性) 。
如果 GetResults 方法成功,結果會傳回 n 個變體的一維陣列,其索引從 0 (0) 到 n - 1。 傳回變體的類型是 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 物件也是同樣的情形。 如果是 Shape 或 Style 物件,則每一個儲存格只需要 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 支援與意見反應。