配列


サンプルソース

Option Explicit

Private Sub Form_Load()

    Dim i As Integer
    
    
    '配列の添え字は0からスタート
    Debug.Print "---------- nArray1 ----------"
    
    Dim nArray1(7) As Integer

    Debug.Print "nArray1 Min = " & LBound(nArray1)
    Debug.Print "nArray1 Max = " & UBound(nArray1)
    
    For i = LBound(nArray1) To UBound(nArray1)
        nArray1(i) = i * 100
        Debug.Print i & " - " & nArray1(i)
    Next i
    
    
    '配列の添え字の最小値と最大値を設定する
    Debug.Print "---------- nArray2 ----------"
    
    Dim nArray2(3 To 5) As Integer

    Debug.Print "nArray2 Min = " & LBound(nArray2)
    Debug.Print "nArray2 Max = " & UBound(nArray2)
    
    For i = LBound(nArray2) To UBound(nArray2)
        nArray2(i) = i * 1000
        Debug.Print i & " - " & nArray2(i)
    Next i

    
    '配列の大きさを変える
    Debug.Print "---------- nArray3 ----------"
    
    ReDim nArray3(0) As Integer
    
    nArray3(0) = 10
    
    Debug.Print "nArray3 Min = " & LBound(nArray3)
    Debug.Print "nArray3 Max = " & UBound(nArray3)
    Debug.Print "0 - " & nArray3(0)
    
    
    ReDim Preserve nArray3(3) As Integer
    
    Debug.Print "nArray3 Min = " & LBound(nArray3)
    Debug.Print "nArray3 Max = " & UBound(nArray3)
    
    nArray3(1) = 100
    nArray3(2) = 200
    nArray3(3) = 300
    
    For i = LBound(nArray3) To UBound(nArray3)
        Debug.Print i & " - " & nArray3(i)
    Next i
    
    
    ReDim Preserve nArray3(7) As Integer
    
    Debug.Print "nArray3 Min = " & LBound(nArray3)
    Debug.Print "nArray3 Max = " & UBound(nArray3)
    
    nArray3(4) = 400
    nArray3(5) = 500
    nArray3(6) = 600
    nArray3(7) = 700
    
    For i = LBound(nArray3) To UBound(nArray3)
        Debug.Print i & " - " & nArray3(i)
    Next i
    

End Sub

 

結果

---------- nArray1 ----------
nArray1 Min = 0
nArray1 Max = 7
0 - 0
1 - 100
2 - 200
3 - 300
4 - 400
5 - 500
6 - 600
7 - 700
---------- nArray2 ----------
nArray2 Min = 3
nArray2 Max = 5
3 - 3000
4 - 4000
5 - 5000
---------- nArray3 ----------
nArray3 Min = 0
nArray3 Max = 0
0 - 10
nArray3 Min = 0
nArray3 Max = 3
0 - 10
1 - 100
2 - 200
3 - 300
nArray3 Min = 0
nArray3 Max = 7
0 - 10
1 - 100
2 - 200
3 - 300
4 - 400
5 - 500
6 - 600
7 - 700

dell17_148x800


<戻る>

PC用眼鏡【管理人も使ってますがマジで疲れません】 解約手数料0円【あしたでんき】 Yahoo 楽天 NTT-X Store

無料ホームページ 無料のクレジットカード 海外格安航空券 ふるさと納税 海外旅行保険が無料! 海外ホテル