I am wanting to take a txt file that I have that is comma separated. For example:
706202212011417.G001,1024,20221201,172300,3600,35479,....
I am trying to figure out how to make an ArrayList and assign each individual comma separated value as an it's own item put it anywhere in the list.
For example, I want to assign the first comma-separated value to an A1
variable, and then use this variable in a MessageBox: "A1 is ******.***"
I have been able to separate everything out, but I cannot seem to set the array to assign each item to its own variable.
Using MyReader As New Microsoft.VisualBasic.
FileIO.TextFieldParser(
"C:\TestFolder\test.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
MsgBox(currentField)
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
Look more closely at the currentRow
variable. This provides an index variable you can use to target individual values in the row: currentRow(0)
, currentRow(1)
, etc.