vb矩阵转置

2024-11-24 13:05:21
推荐回答(2个)
回答1:


Dim a(6, 6) As Integer, i As Integer, ii As Integer

Private Sub Command1_Click()
  For i = 1 To 6
    For ii = 1 To 4
      a(i, ii) = Int(Rnd * 90 + 10)
    Next ii
  Next i

  For i = 1 To 6
    For ii = 1 To 4
      Picture1.Print a(i, ii);
    Next ii
    Picture1.Print ""
  Next i
End Sub

Private Sub Command2_Click()
  For ii = 1 To 4
    For i = 1 To 6
      Picture2.Print a(i, ii);
    Next i
    Picture2.Print
  Next ii
End Sub


回答2:

Option Explicit

Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""

Dim i As Integer
For i = 1 To 24
Text1.Text = Text1 & Int(Rnd * 90) + 10 & " "
If i Mod 4 = 0 Then Text1.Text = Text1.Text & vbCrLf & vbCrLf
Next

End Sub

Private Sub Command2_Click()
Dim a, b, c As Integer, d As Integer
a = Split(Text1.Text, vbCrLf & vbCrLf)

For c = 0 To 3
For d = 0 To 5
b = Split(a(d))
Text2.Text = Text2.Text & b(c) & " "
Next
Text2.Text = Text2.Text & vbCrLf & vbCrLf
Next

End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""

End Sub