2014-03-27 40 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循环之前进行初始化,否则将被重置为初始值和线从读文件将始终走到阵列的同一个插槽