2014-03-27 41 views
0

我試着輸入解析出的所有字符串轉換爲二維數組,其中第5串補一列隨機字符串,然後在未來5組成第二列等。然後我需要隨機選擇3列,並輸出該列中的每個字符串。選擇從分隔文本文件

 path = My.Computer.FileSystem.GetFileInfo("Two_Point_One_Questions.txt") 
    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(path.FullName) 
     MyReader.TextFieldType = FileIO.FieldType.Delimited 
     MyReader.SetDelimiters(",") 
     Dim currentRow As String() 
     While Not MyReader.EndOfData 
      Try 
       currentRow = MyReader.ReadFields() 
       Dim currentField As String 
       Dim i As Integer = 1 
       Dim j As Integer = 1 
       For Each currentField In currentRow 
        Question(i, j) = currentField 
        j = j + 1 
       Next 
      Catch ex As Microsoft.VisualBasic. 
         FileIO.MalformedLineException 
       MsgBox("Line " & ex.Message & 
       "is not valid and will be skipped.") 
      End Try 
     End While 
    End Using 
+0

問題是...? –

+0

您不會增加變量i – Steve

回答

0

我不知道你正在嘗試做的,但你需要增加變量i,填補了問題陣列

 .... 
     End Try 
     i = i + 1 
    End While 
End Using 

順便說上一個新的插槽,數組開始索引零,而不是一個。所以,可能是我的陳述值,y是錯

Dim i As Integer = 0 
Dim j As Integer = 0 

最後,變量i應申報並進入while循環之前進行初始化,否則將被重置爲初始值和線從讀文件將始終走到陣列的同一個插槽