2012-11-19 64 views
0

我將如何去將下面的輸入插入到2d數組中,或者如果需要爲相同效果另外一種數組。多行文本框到2d數組

abcd 
    efgh 
    ijkl 

,當我點擊一個按鈕,我的陣列旋轉90度左右(如果選擇),我一直在想這件事了大約一個小時,我嘗試了一些東西,但我完全新的VB.net

例如使用數字代替:

1 2 3 
4 5 6 
7 8 9 

旋轉:

7 4 1 
8 5 2 
9 6 3 

+0

你能解釋什麼是旋轉陣列? – Steve

+0

@Steve完成後,將示例放在原始帖子中。 – ace007

回答

0

這可能讓你開始你會想動態設置「行」和「列」的上限。這將它輸出到一個文本框中,但將變量分配給一個新數組將很容易。

Dim arr(3, 3) As String 

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 
    Dim i As Integer = 1 
    For row As Integer = 0 To 2 
     For col As Integer = 0 To 2 
      arr(row, col) = i 
      i += 1 
     Next 
    Next 
End Sub 

Public Sub showStraight() 
    TextBox1.Text = "" 
    For row As Integer = 0 To 2 
     Dim line As String = "" 
     For col As Integer = 0 To 2 
      line += arr(row, col) 
     Next 
     TextBox1.Text += line & vbNewLine 
     line = "" 
    Next 
End Sub Public Sub showRotated() 
    TextBox1.Text = "" 
    For col As Integer = 0 To 2 
     Dim line As String = "" 
     For row As Integer = 2 To 0 Step -1 
      line += arr(row, col) 
     Next 
     TextBox1.Text += line & vbNewLine 
     line = "" 
    Next 
End Sub