第14講 高次元配列と低次元配列の関係

第7話 4次元配列を2次元配列で表現する

解答コード例
Private Sub CommandButton1_Click()

  Dim a(2, 3, 4, 5) As Integer
  Dim b(11, 29) As Integer
  Dim i As Integer, j As Integer, k As Integer, l As Integer

  For i = 0 To 2
    For j = 0 To 3
      For k = 0 To 4
        For l = 0 To 5
          a(i, j, k, l) = Int(Rnd * 100)
        Next
      Next
    Next
  Next
  For i = 0 To 2
    For j = 0 To 3
      For k = 0 To 4
        For l = 0 To 5
          Cells(5 + 6 * i + k, 1 + 7 * j + l) = a(i, j, k, l)
        Next
      Next
    Next
  Next

  For i = 0 To 2
    For j = 0 To 3
      For k = 0 To 4
        For l = 0 To 5
          b(4 * i + j, 6 * k + l) = a(i, j, k, l)
        Next
      Next
    Next
  Next
  Dim ii As Integer, kk As Integer
  For i = 0 To 11
    ii = Int(i / 4)
    j = i Mod 4
    For k = 0 To 29
      kk = Int(k / 6)
      l = k Mod 6
      Cells(24 + 6 * ii + kk, 1 + 7 * j + l) = b(i, k)
   Next
  Next

End Sub

実行シート
入門
初心者

ではこの講最後の課題です。
Private Sub CommandButton1_Click()

  Dim a(2, 3, 4, 5) As Integer
  Dim b(11,29) As Integer
  Dim i As Integer, j As Integer, k As Integer, l As Integer

  For i = 0 To 11
    For j = 0 To 29
      b(i, j) = 30 * i + j + 1
    Next
  Next

End Sub
2次元配列のデータを表示し、次に4次元配列に翻訳してから2行下に
4次元配列データを表示させましょう。

第6話へ 第8話へ

004
  


VBA講義第1部へ
vc++講義へ
vb講義へ
VB講義基礎へ
初心者のための世界で一番わかりやすいVisual C++入門基礎講座へ
初心者のための世界で一番わかりやすいVisual aasic入門基礎講座へ

数学研究室に戻る