陣列
您可針對所有資料類型,將含有最多三個維度的本地、模組及全域變數宣告為陣列。
若要宣告陣列,請使用下列語法:
dataType name ( ubound1 [ , ubound2 [ , ubound3] ] )
SPEL+陣列是以零為起始。第一個元素是以零參照。
本地變數的可用陣列元素總數: 字串為200,其他類型則為2000。
全域保留變數的可用陣列元素總數: 字串為400,其他類型則為4000。
全域與模組變數的可用陣列元素總數: 字串為10000,其他類型則為100000。
若要計算陣列中使用的總元素,請使用下列公式。(如果未使用維度,則使用0來替代ubound值。)
總元素 = (ubound1 + 1) * (ubound2 + 1) * (ubound3 + 1)
陣列宣告範例:
' 全域字串陣列
Global String gData$(10)
Function main
' 此函數的區域陣列
Integer intArray(10)
Real coords(20, 10)
使用Redim在運行時間變更陣列外框。
Integer a(10)
Redim a(20)
若要在使用Redim時保留數值,請加入Preserve選用參數。
Integer a(10)
Redim Preserve a(20)
使用UBound取得最大元素數量。
Integer i, a(10)
For i = 1 to UBound(a)
a(i) = i
Next i