您還可以使用利用Evaluate函式和靜態陣列的速記格式.在下面的程式碼中,設定varData,其中[]是Evaluate函式的簡寫,{…}表示式表示靜態陣列.每行用a分隔;每個欄位用a分隔.它可以使您獲得與simoco程式碼相同的最終結果,但語法更接近原始問題:
Sub ArrayShorthand()
Dim varData As Variant
Dim intCounter1 As Integer
Dim intCounter2 As Integer
" set the array
varData = [{1, 2, 3; 4, 5, 6; 7, 8, 9}]
" test
For intCounter1 = 1 To UBound(varData, 1)
For intCounter2 = 1 To UBound(varData, 2)
Debug.Print varData(intCounter1, intCounter2)
Next intCounter2
Next intCounter1
End Sub
您還可以使用利用Evaluate函式和靜態陣列的速記格式.在下面的程式碼中,設定varData,其中[]是Evaluate函式的簡寫,{…}表示式表示靜態陣列.每行用a分隔;每個欄位用a分隔.它可以使您獲得與simoco程式碼相同的最終結果,但語法更接近原始問題:
Sub ArrayShorthand()
Dim varData As Variant
Dim intCounter1 As Integer
Dim intCounter2 As Integer
" set the array
varData = [{1, 2, 3; 4, 5, 6; 7, 8, 9}]
" test
For intCounter1 = 1 To UBound(varData, 1)
For intCounter2 = 1 To UBound(varData, 2)
Debug.Print varData(intCounter1, intCounter2)
Next intCounter2
Next intCounter1
End Sub